【发布时间】:2019-02-14 08:05:08
【问题描述】:
Below is my json file
网址是http://localhost/country.php 我希望这些数据快速进入合适的视图 { 名称:[“印度”,“美国”,“中国”] }
let url = NSURL(string: "http://localhost/country.php")
let userdata = NSData(contentsOf: url! as URL)
do {
let values = try JSONSerialization.jsonObject(with: userdata as! Data, options: .allowFragments) as! NSDictionary
print(values)
print("Parse success")
} catch let error as NSError
{
print(error)
return
}
这是代码 请帮忙
【问题讨论】:
-
到目前为止,您尝试了什么? SO上有很多关于如何快速解析简单JSON的帖子。顺便提一句。你看过你的网址了吗?
-
收到错误“错误域 = NSCocoaErrorDomain 代码 = 3840“字符 2 周围的对象中的值没有字符串键。” UserInfo={NSDebugDescription = 字符 2 周围的对象中的值没有字符串键。}”
-
请向我们展示一些您尝试解析 JSON 的代码以及发生错误的位置(编辑您的问题)
-
查看已编辑的问题
-
不要在没有必要的情况下在
Swift代码中使用NS*类型。
标签: json swift uitableview