gpt4 book ai didi

php - json_encode 不双引号 NULL ; cocoa touch 不当

转载 作者:行者123 更新时间:2023-12-03 16:28:41 26 4
gpt4 key购买 nike

我正在编写一个 native iOS 7 应用程序,需要从 JSON api(由我控制)检索数据。 JSON 输出示例如下:

{
"id" : "544",
"name" : "1900 Green Gables",
"address" : "83 West Main Street",
"city" : "Milford",
"phone" : "(607) 547-1381",
"video_thumb" : null,
"thumbnail" : null,
"s_description" : null
}

我正在使用 php 的 json_encode()转换从我的数据库查询返回的关联数组。在 Objective-c 中我使用 NSJSONSerialization将 JSON 转换为 NSMutableArray 。问题是null值转换为 "<null>" 。我怀疑这是因为json_encode()不是双引号 null值(value)观。我宁愿保留值 null为了保持一致性(在我的 obj-c 代码中检查值是否为 "<null>" 似乎并不可靠)

我知道我可以通过重新调整json_encode()的输出来解决这个问题。 ,但我宁愿避免额外的步骤,并且担心对性能的负面影响。我可以对 PHP、Objective-C 甚至 SQL 查询进行任何更改来解决此问题吗?

最佳答案

<null>[NSNull null] 的字符串化描述,这是 nil 的占位符在 Cocoa 集合中(不能直接包含 nil)。

您应该将该值与 [NSNull null] 进行比较:

if (dictFromJson[@"video_thumb"] != [NSNull null]) {
// do stuff with video thumb here
}

关于php - json_encode 不双引号 NULL ; cocoa touch 不当,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19338297/

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