应对csharp对象错误的json ialialize json-无法从system.string施放或转换为projectName.models.carsmodel
我陷入了棘手的json。 试图将下面的Web API JSON在C#对象中进行挑选。 似乎它没有钥匙,只有以下值。
[“ Toyota”,“ BMW”,“ Nissan”,“ GMC”,“ Mazda”,“ Opel”,“ International”,“ Honda”,“ Honda”,“ Ford”]
以下是我的代码给我错误
var deserializedObject = jsonconvert.deserializeObject< list< carsmodel>>(result);
public class CarsModel
{
[JsonPropertyName("MyJson")]
public List<string>? MyJson { get; set; }
}
'错误转换值“ toyota”将“ toyota”转换为“ carsmodel”。路径'[0]',第1行,位置9
。
I'm stuck with a tricky json.
trying to deserialize below web api json into c# object.
Seems like it has no key, only the below value.
["toyota","bmw","nissan","gmc","mazda","opel","international","honda","ford"]
Below is my code that is giving me error
var deserializedObject = JsonConvert.DeserializeObject<List<CarsModel>>(result);
public class CarsModel
{
[JsonPropertyName("MyJson")]
public List<string>? MyJson { get; set; }
}
'Error converting value "toyota" to type 'CarsModel'. Path '[0]', line 1, position 9.'
ArgumentException: Could not cast or convert from System.String to ProjectName.Models.CarsModel.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请尝试以下代码。
Please try the below code.