C# C中的JSON到数组#
我有一个生成JSON格式的程序。我要做的是将json结果存储到C#中的数组中 json从API接收:C# C中的JSON到数组#,c#,arrays,json,C#,Arrays,Json,我有一个生成JSON格式的程序。我要做的是将json结果存储到C#中的数组中 json从API接收: var strResponseContent = await response.Content.ReadAsStringAsync(); Result.Text = strResponseContent.ToString(); **<-- this is working fine** 并将json存储到数组中。结构如下: public class Intents {
var strResponseContent = await response.Content.ReadAsStringAsync();
Result.Text = strResponseContent.ToString(); **<-- this is working fine**
并将json存储到数组中。结构如下:
public class Intents
{
public List<Intent> intents { get; set; }
}
public class Intent
{
public string intent { get; set; }
public int score { get; set; }
}
公共类意图
{
公共列表意图{get;set;}
}
公共阶级意图
{
公共字符串意图{get;set;}
公共整数分数{get;set;}
}
最后,为了转换,我使用反序列化对象
Intents intents = JsonConvert.DeserializeObject<Intent>(strResponseContent);
Intents-Intents=JsonConvert.DeserializeObject(strResponseContent);
但是,在存储到json的过程中,出现的错误类似于“无法隐式地将类型意图转换为意图”
我犯了什么错?如何纠正它?有两件事第一个分数不是有效的整数。。。所以,尝试将int改为Decimal。 第二,试着这样做:
Intents intents = JsonConvert.DeserializeObject<Intents>(strResponseContent);
Intents-Intents=JsonConvert.DeserializeObject(strResponseContent);
有两件事第一个分数不是有效的整数。。。所以,尝试将int改为Decimal。
第二,试着这样做:
Intents intents = JsonConvert.DeserializeObject<Intents>(strResponseContent);
Intents-Intents=JsonConvert.DeserializeObject(strResponseContent);
您将分数定义为整数
public int score { get; set; }
但分数不是整数。将其更改为双精度或十进制将解决此问题。您将分数定义为整数
public int score { get; set; }
但分数不是整数。将其更改为双精度或十进制将解决此问题。您正在将
Intent
作为类型参数传递给DeserializeObject
您应该传递Intents
的位置。您正在将Intent
作为类型参数传递给DeserializeObject
您应该传递Intents
的位置。我建议将您的答案与我接受了你的答案,看看你错在哪里:-)约翰,我没有错。当我回答这个问题时,杰拉尔多提到了第一个问题。无论他回答什么,我都不想重复。我发现了另一个问题,我提到了它。我觉得这个答案后来通过添加分数问题进行了编辑。我建议将你的答案与公认的答案进行比较,看看你错在哪里:-)约翰,我没有错。当我回答这个问题时,杰拉尔多提到了第一个问题。无论他回答什么,我都不想重复。我发现了另一个问题,我提到了它。我觉得这个答案后来被添加了分数问题。