Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我一直在关注这个教程。我试图将它应用到我的案例中。我将使用的 JSON 提要是:JSON 提要。
他们正在使用以下“查询”:
json[@"loans"][0][@"name"]
因此,我使用以下方法尝试了我的案例:
json[@"0"][@"format"]
或者
json[@"0"][0][@"format"]
但两者都返回null。
我在这里做错了什么?
好吧,因为您拥有的不是 JSON。(即,它是“无效”的 JSON - 例如,它没有用引号括起来的字典键,因此无论您使用什么 JSON 解析器,都可能会返回nil,因为它无法解析它。)
nil
顺便说一句,即使它是有效的 JSON,你的方法也不管用。首先你有一个数组作为根元素,然后它的项目是字典。即,你必须如何索引是
json[0][@"format"]
(前提json是已经解析的对象,而不是 JSON 字符串本身!)
json