JSON Textwriter Formatting



如何使用JsontextWriter ...

格式化此结构
 "truck": {
        "number": "9999",
        "type": "FM",
        "vinNumber": "vin750",
        "licensePlate": {
            "number": "12345",
            "stateProvince": "IN"
        }
    },

我的问题是卡车对象结构中的"许可板"结构。到目前为止,我的代码看起来像这样,但行不通...

 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();

我找到了答案。

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

写入搞砸了...

相关内容

  • 没有找到相关文章

最新更新