gpt4 book ai didi

ios - 将 NSData(Json 数据)转换为 nsarray : iOS

转载 作者:行者123 更新时间:2023-11-28 18:19:11 24 4
gpt4 key购买 nike

我正在从 WebService 获取一些数据(这是一个 json 数据)

Webservice 发送的准确输入是:

[
{
"id": "C-62",
"title": "testing testing",
"type": "image",
"thumb": "",
"LinkId": "ABC",
"fileSize":1074,
"level":0,
},
{
"id": "C-63",
"title": "testing ab testing",
"type": "audio",
"thumb": "",
"LinkId": "ABCD",
"fileSize":1074,
"level":1,
}

]

我在输入数据中看到只有fileSize是整数类型的Key-Value对其余均为字符串格式。

当我使用以下代码将该 NSData 转换为 NSArray 时

 NSArray *dataArray = nil;

dataArray = [NSJSONSerialization JSONObjectWithData:data
options:0
error:nil];

我得到这样的“dataArray”

{
"id": "C-62",
"title": "testing testing",
"type": image,
"thumb": "",
"LinkId": "ABC",
"fileSize":1074,
"level":0,
},
{
"id": "C-63",
"title": "testing ab testing",
"type": audio,
"thumb": "",
"LinkId": "ABCD",
"fileSize":1074,
"level":1,
}

“类型”键值对更改为“int”。所有其他键值对处于相同状态。

请帮助我将输入数据转换为与网络服务发送的格式相同的格式。我正在使用 iOS 7。

最佳答案

你只是把自己弄糊涂了。您将 NSLog 输出与实际存储的内容混淆了。当您声称只有“fileSize”字段包含数字时,您也没有说实话,因为显然“level”字段也是如此。

NSLog 仅在必要时显示带引号的字符串。字符串“10”将显示为不带引号的 10。你真的可以相信 NSJSONSerializer 不会在你背后做任何事情。

关于ios - 将 NSData(Json 数据)转换为 nsarray : iOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23892093/

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