我有一个像这样的 json 对象数组:
[{
"Time-VitalsTime": "2019-06-22T01:01:00",
"TimeToEstimate-VitalsTime": 10,
"TimeToEstimate-1unit": 5,
"TimeToEstimate-2units": 9,
"TimeToEstimate-3units": 21,
"TimeToEstimate-1week": 13,
"TimeToEstimate-2weeks": 16,
"TimeToEstimate-3weeks": 20
}, {
"Time-VitalsTime": "2019-06-22T01:02:00",
"TimeToEstimate-VitalsTime": 8,
"TimeToEstimate-1unit": 10,
"TimeToEstimate-2units": 5,
"TimeToEstimate-3units": 9,
"TimeToEstimate-1week": 18,
"TimeToEstimate-2weeks": 15,
"TimeToEstimate-3weeks": 32
}, {
"Time-VitalsTime": "2019-06-22T01:03:00",
"TimeToEstimate-VitalsTime": 10,
"TimeToEstimate-1unit": 8,
"TimeToEstimate-2units": 10,
"TimeToEstimate-3units": 5,
"TimeToEstimate-1week": 15,
"TimeToEstimate-2weeks": 14,
"TimeToEstimate-3weeks": 16
},
我需要把它变成这个形状(根据 api 文档):
{
"data":
[
<model-specific-data-structure>
]
}
然后我用这个:
request.Content = new StringContent(JsonConvert.SerializeObject(stringgeneratedabove));
将其序列化以发送到 REST api。我从通话中得到的错误是:“{\”错误\”:\“字符串索引必须是整数\”}”
一位朋友说我需要将数组传递到名为“data”的属性中。在网上进行了大量搜索后,我不知道从哪里开始。我尝试做这样的事情:
[DataContract]
public class CsvDataClass
{
[DataMember]
public List<Dictionary<object, object>> CsvData { get; set; }
[DataMember]
public Dictionary<object, object>[] Data
{
get { return CsvData.ToArray(); }
}
}
根据朋友的说法,但无法实施。我搜索过“更改 json c# 的形状”或“将 json 数组传递到属性”,并且还阅读了有关 json 对象的一般文档,但尚未单击任何内容。
慕田峪9158850
相关分类