2013-02-12 30 views
0

使用SBJSON解析器解析從服務器JSON的價值,我已經收到響應像如何解析iPad中的JSON值?

-(void)connectionDidFinishLoading:(NSURLConnection *)connection 
{ 

NSString *json_string = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; 

json_string值這裏:

{ "status": true, "result": { "nid": "1116", "title": "PeopleSoft Enterprise HCM 91 Release Notes.pdf", "status": "1", "uid": "1", "body": "\x3cp\x3e\x3ca href=\"http://www.carinsuranceiseasy.com/\"\x3echeapest auto insurance\x3c/a\x3e wttig \x3ca href=\"http://www.lifeinsuranceshopping.net/\"\x3elife insurance quotes\x3c/a\x3e 304 \x3ca href=\"http://www.bestautoinsurancepolicies.net/\"\x3eaffordable auto insurance\x3c/a\x3e 39292\x3c/p\x3e", "splitpdfs": [ ], "mail": "[email protected]", "name": "admin", "pdf": "http://www.publishgenie.com/sites/default/files/pdf_convert/2012/12/19/1355908128-986.pdf", "page_number": "249", "filesize": 8936895, "referrallink": "http://www.publishgenie.com/index.php?q=ebook-referral/530/1116/19f80281e0ad314423afb51a5322e2ac" } } 

然後我試圖在NSDictionary的設定值,但dictionar值總是空,如何解析這個?請幫幫我。

由於提前

我嘗試這樣做:

SBJSON * parser = [[SBJSON alloc] init]; 
    NSDictionary *dic = (NSDictionary *)[parser objectWithString:json_string error:nil]; 

回答

0

是否有您使用SBJSON理由嗎?您可以在解析器使用編譯:

id jsonObject = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error]; 

編輯: 你也JSON字符串是無效的。 You can use a site like this to check you json

+0

感謝您的回覆 – SampathKumar 2013-02-13 06:07:45