解析json时出错

时间:2014-11-13 07:46:50

标签: ios iphone json ios7 xcode5

我已经编写了解析json的代码。

NSData *getData = [NSURLConnection sendSynchronousRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.xxxxxx.com/json/ajax/getArtist.json.php?songId=452"]] returningResponse:nil error:&error1];
BOOL isTurnableToJSON = [NSJSONSerialization isValidJSONObject: getData];
NSLog(@"isTurnableToJSON: %d", isTurnableToJSON);

id  jsonData = [NSJSONSerialization JSONObjectWithData:getData options:NSJSONReadingAllowFragments error:&error];
NSLog(@"Data===%@",jsonData);
NSLog(@"Error===%@",error);

并收到错误

Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed. (Cocoa error 3840.)" (Invalid value around character 0.) UserInfo=0xa8dd6b0 {NSDebugDescription=Invalid value around character 0.}

和json回复

{"trackDetails":[{"trackTitle":"Faghat Be Eshghe To","artist":"Babak Jahanbakhsh","albumName":"Oxygen","likes":"0","loves":"0","albumImage":"http:\/\/www.xxxxxxx.com\/files\/albums\/audio\/thumbs\/105x105\/a6f69b486abc27e13f2c23c9283da606.jpg","url":"http:\/\/www.xxxxxx.com\/files\/music\/446\/aafe6fff1f8d9313e560dce0eeb70e37.mp3","finishTime":"838"}]}

我检查了http://jsonlint.com/中的json 这个网站的回复是有效的json Plz帮助

0 个答案:

没有答案