我有一个我从JSON获得的字符串。
{
"Audit_Description": "Request Approved",
"Module_Name": "Resource Request",
"Field_DisplayName": null",
"Previous_Value": Education",
"Current_Value": Employment",
"Modified_Timestamp": "08-02-2013"
},
{
"Audit_Description": "Request Approved",
"Module_Name": "Resource Request",
"Field_DisplayName": null",
"Previous_Value": null",
"Current_Value": null",
"Modified_Timestamp": "08-02-2013"
}
我想解析数据。从JSON
开始,数据如上所述NSString
。
我想将它们作为密钥对值提取出来。但是我无法解析它们。
这应该像NSMutableDictionary
一样转换
密钥"Audit_Description"
的值应为"Request Approved"
输出:
@{
@"Audit_Description" : @"Request Approved",
@"Module_Name" = @"Resource Request",
@"Field_DisplayName" : <null>,
@"Previous_Value" : @"Education",
@"Current_Value" : @"Employment",
@"Modified_Timestamp" : @"08-02-2013"
}
感谢。
答案 0 :(得分:11)
NSError *err = nil;
NSArray *arr = [NSJSONSerialization JSONObjectWithData:[str dataUsingEncoding:NSUTF8StringEncoding] options:NSJSONReadingMutableContainers error:&err];
// access the dictionaries
NSMutableDictionary *dict = arr[0];
for (NSMutableDictionary *dictionary in arr) {
// do something using dictionary
}
由于NSJSONReadingMutableContainers,它创建了一个可变字典。