2011-06-13 185 views
0

顯示標籤動態這是我的JSON響應:從JSON響應

{"#error":false, 
"#data": 
    {"personal_info": 
     {"basic_information": 
      {"EmailAddress":"[email protected]", 
      "PasionProfessional":null, 
      "PasionPersonal":null, 
      "WorkLocation":"Chennai-AMB-6, Amb. Ind. Est., MTH Rd, 8", 
      "Country":null, 
      "City":null, 
      "Latitude":null, 
      "Longitude":null, 
      "Title":"Software Engineer", 
      "HomeTown":null, 
      "RelationshipStatus":null, 
      "BriefBio":null, 
      "FavouriteQuotation":null}, 
     "education": 
      {"HighSchool":null, 
      "HighSchoolYear":null, 
      "HigherSecondary":null, 
      "HSSYear":null, 
      "DiplomaTechnical":null, 
      "DiplomaInsitute":null, 
      "YearofDiploma: ":null, 
      "Degree":null, 
      "YearofPassing":null, 
      "College/University":null, 
      "PostGraduation":null, 
      "YearofPostGraduation":null, 
      "PGCollege/University":null}, 
     "interest": 
      {"Keywords":null}, 
     "contact_information": 
      {"MobilePhone":"9791729428", 
      "BusinessCode":null, 
      "BusinessPhone":null, 
      "OtherCode":null, 
      "OtherPhone":null, 
      "Website":null}}, 
    "work_profile_info": 
     {"profile_title":"", 
     "profile_bio":""}, 
    "boolean":"1"}} 

現在我想這樣的編程方式顯示標籤:

EmailAddress   [email protected] 
PasionProfessional Nil 

我怎麼能這樣做?

+1

你必須寫一個特定的Javascript功能來分析您的JSON結果。你可以簡單地使用string.format來達到理想的結果。請參閱:http://stackoverflow.com/questions/6332391/javascript-for-loop-through-json-values – kanchirk 2011-06-13 15:41:06

+0

對於理解這個問題kanchirk +1! – 2011-06-13 16:03:00

+0

真的不知道JavaScript與此有什麼關係...... – 2011-06-13 17:48:08

回答

0

非常容易。你需要一個JSON庫,允許你解析你收到的數據。我個人喜歡JSONKit

NSURL *url = [NSURL URLWithString:@"http://url.com"]; 
NSData *data = [NSData dataWithContentsOfURL:url]; 
NSDictionary *dict = [data objectFromJSONString]; //JSONKit 

然後,你可以下臺結構,抓住你想要的東西:

NSString *email = [dict valueForKeyPath:@"#data.personal_info.basic_information. EmailAddress"]; 
+0

然後,您使用'setText:'方法將這些字符串設置爲標籤。 – 2011-06-13 18:18:36