Json 在Swift中解析PHP Web服务Replt
我是Swift新手,但我正在尝试使用基于PHP的web服务返回回复:-Json 在Swift中解析PHP Web服务Replt,json,swift,Json,Swift,我是Swift新手,但我正在尝试使用基于PHP的web服务返回回复:- { responseData = { 1 = { name = "3D SYSTEMS CORP"; result = success; }; 10 = { name = "ABERCROMBIE & FITCH CO-CL A";
{
responseData = {
1 = {
name = "3D SYSTEMS CORP";
result = success;
};
10 = {
name = "ABERCROMBIE & FITCH CO-CL A";
result = success;
};
};
}
我假设这是一种有效的JSON格式,但无法解决如何将这个数据加载到字符串数组中,而这个数据只是一个字符串列表。我有这样的trie代码来迭代一个rte元素,但没有成功
let url = urlComponents.URL
let task = NSURLSession.sharedSession().dataTaskWithURL(url!) {
(data, response, error) -> Void in
if let urlContnet = data
{
do {
let jsonResult = try NSJSONSerialization.JSONObjectWithData(urlContnet, options: NSJSONReadingOptions.MutableContainers)
if let nudges = jsonResult["responseData"] as? NSArray {
for nudge in nudges {
print(nudge)
}
}
}
catch
{
print("ERROR")
}
}
}
task.resume()
有人能帮忙吗
谢谢
史蒂夫这里有两件事
{
"responseData": {
"1": {
"name": "3D SYSTEMS CORP",
"result": "success"
},
"10": {
"name": "ABERCROMBIE & FITCH CO-CL A",
"result": "success"
}
}
}
HTH谢谢,我正在使用第三方web服务,因此无法控制格式,是否有任何方法可以使用当前的响应格式处理此问题,谢谢您的帮助