Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/40.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 将JSON格式的NSString转换为NSMutableDictionary_Iphone_Json_Nsstring_Nsmutabledictionary - Fatal编程技术网

Iphone 将JSON格式的NSString转换为NSMutableDictionary

Iphone 将JSON格式的NSString转换为NSMutableDictionary,iphone,json,nsstring,nsmutabledictionary,Iphone,Json,Nsstring,Nsmutabledictionary,我有一个来自JSON的字符串 { "Audit_Description": "Request Approved", "Module_Name": "Resource Request", "Field_DisplayName": null", "Previous_Value": Education", "Current_Value": Employment", "Modified_Timestamp": "08-02-2013" }, {

我有一个来自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
like中进行转换 对于键
“审核描述”
值应为
“请求已批准”

输出:

  @{
      @"Audit_Description" : @"Request Approved",
      @"Module_Name" = @"Resource Request",
      @"Field_DisplayName" : <null>,
      @"Previous_Value" : @"Education",
      @"Current_Value" : @"Employment",
      @"Modified_Timestamp" : @"08-02-2013"
  }
@{
@“审核说明”:@“请求已批准”,
@“模块名称”=@“资源请求”,
@“字段显示名称”:,
@“以前的价值观”:“教育”,
@“当前价值”:“就业”,
@“修改的_时间戳”:@“08-02-2013”
}
谢谢

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,这就创建了一个可变字典。

我用2个dict获得了mutableArray,我应该如何从数组中提取每个对象。我尝试了类型转换,但没有完成。它们不是键和值对,因为您的结构是一个带字典的数组。您可以循环它们来获取每一个,或者直接访问一个位置,就像任何数组一样:arr[0]。该死,这样行吗?下一次完全用这个谢谢!