gpt4 book ai didi

iphone - 将 JSON 格式的 NSString 转换为 NSMutableDictionary

转载 作者:行者123 更新时间:2023-12-03 20:20:05 25 4
gpt4 key购买 nike

我有一个从 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 中。我想将它们提取为 key 对值。但我无法解析它们。这应该像 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"
}

谢谢。

最佳答案

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

关于iphone - 将 JSON 格式的 NSString 转换为 NSMutableDictionary,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15223220/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com