gpt4 book ai didi

ios - 错误解析 JSON 错误 3840

转载 作者:行者123 更新时间:2023-11-28 22:01:34 26 4
gpt4 key购买 nike

我有一个返回 VALID JSON 数组的网络服务,但在我的代码中出现以下错误。

"Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed. (Cocoa error 3840.)" (JSON text did not start with array or object and option to allow fragments not set.) UserInfo=0x9b9af50 {NSDebugDescription=JSON text did not start with array or object and option to allow fragments not set.}"

我知道这个错误是由于json中的错误。但我已经检查并验证了他们认为有效的各种来源的回复。

这是我的 JSON Objective-C 代码

NSDictionary *dictionary = [NSDictionary dictionaryWithJSONData:jsonData];

我也用这段代码来获取字典

NSDictionary *dictionary = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&err];

但是当我调试并检查字典变量时,它显示“nil”

这是我的 json 响应

[  
{
"id":"182",
"name":"2 Tone Brown",
"price":"2099.0000",
"description":"",
"image":"http:\/\/www.nnn.com\/images\/2 Tone BG.jpg",
"images":[
{
"1":"2 Tone BG 1.jpg"
},
{
"2":"2 Tone BG 2.jpg"
},
{
"3":"2 Tone BG 3.jpg"
},
{
"4":"2 Tone BG 4.jpg"
},
{
"5":"2 Tone BG 5.jpg"
}
],
"sizes":[
{
"id":"16",
"size":"L",
"price":"0.0000"
},
{
"id":"17",
"size":"XL",
"price":"200.0000"
},
{
"id":"15",
"size":"M",
"price":"0.0000"
},
{
"id":"14",
"size":"S",
"price":"0.0000"
},
{
"id":"23",
"size":"Custom Size",
"price":"100.0000"
},
{
"id":"42",
"size":"Please Select",
"price":"0.0000"
}
]
},
{
"id":"293",
"name":"3 Seam Collar Black",
"price":"2499.0000",
"description":"Exclusive 3 Collar <br> <br> This beautiful but simple color combination gives you a great look. <br> <br> Colors: Red\/Black, Green\/Blue Check, Sky Blue",
"image":"http:\/\/www.nnn.com\/images\/3 Seam Collar Black Main.jpg",
"images":[
{
"1":"3 Seam Collar Black 1.jpg"
},
{
"2":"3 Seam Collar Black 6.jpg"
},
{
"3":"3 Seam Collar Black 2.jpg"
},
{
"4":"3 Seam Collar Black 3.jpg"
},
{
"5":"3 Seam Collar Black 5.jpg"
},
{
"6":"3 Seam Collar Black 4.jpg"
}
],
"sizes":[
{
"id":"17",
"size":"XL",
"price":"200.0000"
},
{
"id":"16",
"size":"L",
"price":"0.0000"
},
{
"id":"15",
"size":"M",
"price":"0.0000"
},
{
"id":"14",
"size":"S",
"price":"0.0000"
},
{
"id":"23",
"size":"Custom Size",
"price":"100.0000"
}
]
}
]

上面的 JSON 在 java 中运行良好,但不会产生任何结果。

最佳答案

由于您的 JSON 被 [...] 包围,它将返回一个数组,而不是字典。

关于ios - 错误解析 JSON 错误 3840,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24970821/

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