Writing Json using Newtonsoft.json.JsonTextWriter

后端 未结 1 1086
心在旅途
心在旅途 2021-02-19 06:42

I am writing a json using Newtonsoft.json.JsonTextWriter. Here is my code:

StringBuilder sb = new StringBuilder();
StringWriter sw = new StringWriter(sb);
JsonWr         


        
相关标签:
1条回答
  • 2021-02-19 07:27

    My answer is now not relevant, since the code sample in the question has been edited to include these lines, left here for posterity, see comments for more info.


    You will need to add the following to close the JSON elements properly:

    jsonWriter.WriteEndObject();
    

    Then call the StringBuilder's ToString() method:

    string strMyString = sb.ToString(); //JSONString
    

    References:

    StringWriter Constructor (MSDN) | Reading and Writing JSON (NewtonKing.com)

    0 讨论(0)
提交回复
热议问题