2011-07-26 53 views
0

我正在Iphone上首次使用JSON解析。我需要解析如下JSON字符串:用Iphone解析json

{ 
EmpMaster : 
[ 
    {"empId" : 1,"firstName" : "Yogesh","lastName":"Chaudhari","isSupervisor" : "1","supervisorId":"1"}, 
    {"empId" : 2,"firstName" : "Sahil","lastName":"Khurana","isSupervisor" : "1","supervisorId":"1"}, 
    {"empId" : 3,"firstName" : "Anutag","lastName":"Chaudhari","isSupervisor" : "1","supervisorId":"1"}, 
    {"empId" : 4,"firstName" : "Sameer","lastName":"Vaidya","isSupervisor" : "1","supervisorId":"1"} 
] 
} 

请为我提供了一些示例代码或链接在其帮助下,我可以解析JSON字符串并分离EMPID,名字,姓氏,isSupervisor和supervisorId。

回答

4

您需要添加JSON Framework。它将简单地解析你的JSON字符串,并返回你所有的密钥NSDictionary。

this link

1. Open Folder and rename Classes folder to "JSON". 
2. Copy JSON Folder and include in your project. 
3. Import header file like below in controller where you want to parse JSON String. 

#import "SBJSON.h" 
#import "NSString+SBJSON.h" 

4. Now, Parse your response string in to NSDictionary like below. 

    NSMutableDictionary *dictResponse = [strResponse JSONValue]; 

希望这有助于改进

下载Zip文件。

+0

嗨Deeps.Can请给我一些示例代码来解析上面的json字符串吗?我是相当新的使用iphone上的json –

+0

@Shraddha Harne看看发送的链接和其他答案建议的教程。 Stackoverflow不是复制和粘贴源代码库。 –

+0

@Shraddha我修改了我的答案。希望有所帮助。 – Deeps

-1

最流行的框架之一是touchJSON。易于添加,易于使用。