JSON Textwriter格式

时间:2016-12-01 17:12:33

标签: json textwriter

如何使用JsonTextWriter格式化此结构...

 writer.WriteStartObject();
    writer.WritePropertyName("data");
    writer.WriteValue("TEST");
    writer.WritePropertyName("tripNumber");
    writer.WriteValue("TTEST001");
    writer.WritePropertyName("estimatedArrivalDateTime");
    writer.WriteValue(new DateTime(2014, 01, 14, 15,20,00));
    writer.WritePropertyName("truck");
    //writer.WriteRaw("{");
    writer.WriteStartObject();
            writer.WritePropertyName("number");
            writer.WriteValue("123");
            writer.WritePropertyName("type");
            writer.WriteValue("FM");
            writer.WritePropertyName("vinNumber");
            writer.WriteValue("vintest1234");
            writer.WritePropertyName("licensePlate");
            writer.WriteEnd();
            //writer.WriteEndObject();
            writer.WritePropertyName("number");
            writer.WriteValue("truck plate#");
            writer.WritePropertyName("stateProvince");
            writer.WriteValue("IN");
            writer.WriteEndObject();

我的问题是" licensePlate"卡车对象结构内的结构.. 到目前为止我的代码看起来像这样但不起作用......

inline void myfunc(double v1, ... , double vN){
  ...
  (general, complex, multiline manipulation of v1 .. vN)
  ...
  res = v1;
}

1 个答案:

答案 0 :(得分:1)

我找到了答案..

   writer.WritePropertyName("licensePlate");
            writer.WriteStartObject();
            writer.WritePropertyName("number");
            writer.WriteValue("truck plate#");
            writer.WritePropertyName("stateProvince");
            writer.WriteValue("IN");
            writer.WriteEndObject();

WriteEnd搞砸了......