如何阅读JSON对象

时间:2011-09-23 06:52:08

标签: iphone objective-c json

我有一个像

这样的JSON对象
{"status":"200","id":"23","username":"nipinponmudi@gmail.com","fname":"hh","laname":"hh","timezone":"2","createdate":"2011-09-20 22:05:24","key":"db3f57a8f2b9abd9d51916232f5a77b9"}

上面的对象是来自服务器的响应。我想在viewdidload方法的相应文本字段中显示这些对象。我想读取这个对象并在textfield中单独显示。我需要只提取用户名,fname,lname 。不需要阅读状态

1 个答案:

答案 0 :(得分:2)

看看https://github.com/stig/json-framework/。我相信他们有很多来源和例子可以告诉你。

NSString *jsonString = @{"status":"200","id":"23","username":"nipinponmudi@gmail.com","fname":"hh","laname":"hh","timezone":"2","createdate":"2011-09-20 22:05:24","key":"db3f57a8f2b9abd9d51916232f5a77b9"}";
SBJsonParser *parser = [SBJsonParser new];
id object = [parser objectWithString:jsonString];

txtName.text = [object objectForKey:@"username"];