누구나 IOS5에서 json 데이터를 구문 분석하는 방법을 알려줄 수 있습니까? 아래 JSON 데이터를 제공하고 있습니다.IOS5에서 JSON 데이터를 구문 분석하는 방법
{
"fieldType" : "Alphanumeric",
"fieldName" : "Name"
},{
"fieldType" : "Numeric",
"fieldName" : "Card Num"
},{
"fieldType" : "Alphanumeric",
"fieldName" : "Pin Num"
}
올바른 JSON 형식입니까? 또는 JSON 형식을 변경해야합니까?
The operation couldn’t be completed. (Cocoa error 3840.)
코드 내가 사용 :
NSError *error = nil;
NSData *jsonData = [filedList dataUsingEncoding:[NSString defaultCStringEncoding]];
if (jsonData)
{
id jsonObjects = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&error];
if (error)
{
NSLog(@"error is %@", [error localizedDescription]);
// Handle Error and return
return;
}
NSArray *keys = [jsonObjects allKeys];
// values in foreach loop
for (NSString *key in keys)
{
NSLog(@"%@ is %@",key, [jsonObjects objectForKey:key]);
}
}
else
{
// Handle Error
}
http://jsonlint.com을 사용하여 JSON의 유효성을 검사하십시오. 유효하지 않습니다. –