我正在尝试用Objective C解析一些Json。
我的问题是我得到了正确的 json,但是当我尝试解析一些 json 时,我的应用程序崩溃了。
// i will use a code from connect to DB tutorial
NSString *strURL = [NSString stringWithFormat:@"http://www.ddproam.co.za/Central/Asset/AssetsWithSerial?Serial=S00000001"];
// to execute php code
NSData *dataURL = [NSData dataWithContentsOfURL:[NSURL URLWithString:strURL]];
// to receive the returend value
NSString *strResult = [[NSString alloc] initWithData:dataURL encoding:NSUTF8StringEncoding];
NSLog(@"Login response:%@",strResult);
NSError *error;
//parse out the json data
NSDictionary* json = [NSJSONSerialization JSONObjectWithData:dataURL //1
options:kNilOptions
error:&error];
NSArray* defineJsonData = [json objectForKey:@"AssetDesc"]; //2
NSLog(@"value: %@", defineJsonData); //3
这是我的json:
[{"AssetID":1,"AssetName":"Asset 1","AssetDesc":"This is a manually inserted Asset","AssetTypeID":1,"AssetTypeDesc":"This is a manually inserted Asset Type"}]
我正在尝试从字符串中取出 AssestName。我一定做错了什么。