【发布时间】:2020-11-01 12:56:52
【问题描述】:
我有一个字符串(下面的 sn-p),我知道它是 parsing it here 的有效 json。我想要实现的最终解析是based off this PHP code。当我尝试以下代码时,我似乎无法让 xcode 保持快乐,因为我似乎继续制作 <Any> 的数组,要么得到错误 Value of type 'Any' has no subscripts 要么解包 nil
任何想法如何解析这个将不胜感激。
if let jsonArray = try JSONSerialization.jsonObject(with: jsonString.data(using: .utf8)!,options : .allowFragments) as? Array<Any> {
let a = jsonArray[0] as? Array<Any>
let a = jsonArray[0] as? Array<Any>
let b = a?[1] as? Array<Any>
let c = b?[1] as? Array<Array<Any>>
}
片段 - full string here
[["comic books",[["","","","","","","","","Ba6eX5HWBc3btAa6mJ_4Cg","0ahUKEwjR7NSWsOHsAhXNLc0KHTrMB68QmBkIAigA",["comic books",0]
]
,["","","","","","","","","Ba6eX5HWBc3btAa6mJ_4Cg","0ahUKEwjR7NSWsOHsAhXNLc0KHTrMB68QmBkIBCgB","","","","",["Ba6eX5HWBc3btAa6mJ_4Cg","0ahUKEwjR7NSWsOHsAhXNLc0KHTrMB68Q8BcIBSgAMAA",["330 Army Trail Rd","Glendale Heights, IL 60139"]
,"",["","","",["https://www.google.com/search?q\u003dGot+Comics+Inc,+330+Army+Trail+Rd,+Glendale+Heights,+IL+60139\u0026ludocid\u003d7330282631276370350#lrd\u003d0x880fac8c25bbd32b:0x65ba6537347199ae,1","105
【问题讨论】:
-
那是糟糕的 JSON 格式。
-
哦,是的……