我正在尝试解码Swift中的JSON树,下面的文本是JSON树的样子:
{
"_type" = News;
queryContext = {
originalQuery = "";
};
readLink = "https://api.cognitive.microsoft.com/api/v7/news/search?q=";
value = (
{
ampUrl = "https://www.msn.com/en-us/news/us/its-no-different-from-new-york-urban-centers-nationwide-gird-for-catastrophic-virus-outbreak/amp/ar-BB11QzZ6?li=BBnb7Kz";
category = Health;
datePublished = "2020-03-28T18:36:05.0000000Z";
description = "In Chicago, the Army Corps of Engineers was preparing to erect 2,500 patient quarters throughout three of the cavernous halls at McCormick Place, the largest convention center in North America. In Detroit, a major hospital system was readying a letter for patients and their families outlining how scarce ventilators would be allocated, saying ...";
headline = 1;
image = {
thumbnail = {
contentUrl = "https://www.bing.com/th?id=ON.0EDDB46C77D1689214EC5B7940C23A91&pid=News";
height = 367;
width = 700;
};
};
name = "U2018ItU2019s no different from New YorkU2019: Urban centers nationwide gird for catastrophic virus outbreak";
provider = (
{
"_type" = Organization;
image = {
thumbnail = {
contentUrl = "https://www.bing.com/th?id=AR_04bc0c1c424cf64dec14a2982f0360ef&pid=news";
};
};
name = "The Washington Post on MSN.com";
}
);
我的数据解码结构如下所示:
struct Articles: Decodable {
let values: [String: String]
let name: String
}
我的终端告诉我"name"的值不存在。我的数据是否低于"值"?
像这样更改Struct
:
struct Articles: Decodable {
let readLink: String
let value: [Values]
}
struct Values: Decodable {
let description: String
let name: String
}
名称在值数组内。
你想解码哪个名字?提供程序数组中还有一个。