开发者

Displaying labels dynamically from JSON response

This is my JSON response:

{"#error":false,
 "#data":
    {"personal_info":
        {"basic_information":
            {"Ema开发者_StackOverflow中文版ilAddress":"k_bhuvaneswari@hcl.com",
             "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"}}

Now I want to display labels programmatically like this:

EmailAddress          k_bhuvaneswari@hcl.com
PasionProfessional    Nil

How can I do that?


Very easy. You need a JSON library that allows you to parse the data you recieve. I personally like JSONKit.

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

Then you can just step down the structure and grab the stuff you want:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜