我希望将这个JSON字符串数组发送到我的API。我几乎没有问题......
要发送的身体是:
[
{
"ObjectId" : "1270583B-208A-427F-8B1E-B20E6271D0FE",
"ObjectTypeId" : 1
},
{
"ObjectId" : "1270583B-208A-427F-8B1E-B20E6271D0FE",
"ObjectTypeId" : 2
},
{
"ObjectId" : "1270583B-208A-427F-8B1E-B20E6271D0FE",
"ObjectTypeId" : 3
}
]
我的模特课是:
class Model
{
public string ObjectId { get; set; }
public int ObjectTypeId { get; set; }
}
我正在反编译我的Httpcontent:
static object Content;
string HttpContent= "[{\"ObjectId\" : \"1270583B-208A-427F-8B1E- B20E6271D0FE\" , \"ObjectTypeId\" : 1 }]";
Content = JsonConvert.DeserializeObject<Model>(Httpcontent);
答案 0 :(得分:1)
您应该尝试将其反序列化为Model对象列表。
Content = JsonConvert.DeserializeObject<List<Model>>(Httpcontent);
答案 1 :(得分:0)
解决方案是将[]添加到我的模型中。谢谢@ Johannes.colmsee
Content = JsonConvert.DeserializeObject<Model[]>(Httpcontent);