2011-07-26 88 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。易於添加,易於使用。