Json 响应仅获取 swift 中的最后一行
Json response gets only last row in swift
嗨,我正在尝试从服务器获取子响应,以下是我在使用邮递员时从服务器获得的响应
{
"stories": [
{
"image_url": "http://storybox.dk/wp-content/uploads/2016/11/Hansa.jpg",
"name": "New story",
"story_key": "ahJlfnN0b3J5Ym94LWJhY2tlbmRyEgsSBVN0b3J5GICAgIC8oYIKDA"
},
{
"image_url": "http://storybox.dk/wp-content/uploads/2016/11/Hansa.jpg",
"name": "Story of Foo the fox.",
"story_key": "ahJlfnN0b3J5Ym94LWJhY2tlbmRyEgsSBVN0b3J5GICAgID4woQKDA"
}]
}
但是当我尝试将 stories 标签内的值作为数组获取时,它只获取一个值作为
self.StoryListArr = (reponsedict.value(forKey: "stories") as?NSArray)!
(
{
"image_url" = "http://storage.googleapis.com/storybox-backend.appspot.com/5649391675244544/Screenshot_from_2017-03-16_113338.png";
name = "Story of Foo";
"story_key" = ahJlfnN0b3J5Ym94LWJhY2tlbmRyEgsSBVN0b3J5GICAgID4woQKDA;
}
)
请指教如何处理这个问题
当我尝试打印响应字典时,它只显示其中的一个值
{
stories = (
{
"image_url" = "http://storage.googleapis.com/storybox-backend.appspot.com/5649391675244544/Screenshot_from_2017-03-16_113338.png";
name = "Story of Foo";
"story_key" = ahJlfnN0b3J5Ym94LWJhY2tlbmRyEgsSBVN0b3J5GICAgID4woQKDA;
}
);
}
没有理由在Swift中使用NSArray。只需将对象投射到 [Dictionary].
if let stories = responsedict["stories"] as? [Dictionary<String,String>] {
print(stories)
}
嗨,我正在尝试从服务器获取子响应,以下是我在使用邮递员时从服务器获得的响应
{
"stories": [
{
"image_url": "http://storybox.dk/wp-content/uploads/2016/11/Hansa.jpg",
"name": "New story",
"story_key": "ahJlfnN0b3J5Ym94LWJhY2tlbmRyEgsSBVN0b3J5GICAgIC8oYIKDA"
},
{
"image_url": "http://storybox.dk/wp-content/uploads/2016/11/Hansa.jpg",
"name": "Story of Foo the fox.",
"story_key": "ahJlfnN0b3J5Ym94LWJhY2tlbmRyEgsSBVN0b3J5GICAgID4woQKDA"
}]
}
但是当我尝试将 stories 标签内的值作为数组获取时,它只获取一个值作为
self.StoryListArr = (reponsedict.value(forKey: "stories") as?NSArray)!
(
{
"image_url" = "http://storage.googleapis.com/storybox-backend.appspot.com/5649391675244544/Screenshot_from_2017-03-16_113338.png";
name = "Story of Foo";
"story_key" = ahJlfnN0b3J5Ym94LWJhY2tlbmRyEgsSBVN0b3J5GICAgID4woQKDA;
}
)
请指教如何处理这个问题
当我尝试打印响应字典时,它只显示其中的一个值
{
stories = (
{
"image_url" = "http://storage.googleapis.com/storybox-backend.appspot.com/5649391675244544/Screenshot_from_2017-03-16_113338.png";
name = "Story of Foo";
"story_key" = ahJlfnN0b3J5Ym94LWJhY2tlbmRyEgsSBVN0b3J5GICAgID4woQKDA;
}
);
}
没有理由在Swift中使用NSArray。只需将对象投射到 [Dictionary].
if let stories = responsedict["stories"] as? [Dictionary<String,String>] {
print(stories)
}