2011-06-13 189 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