Get Raw json string in Newtonsoft.Json Library

后端 未结 6 1202
别那么骄傲
别那么骄傲 2020-12-11 01:42

I have json like this

{
    \"name\": \"somenameofevent\",
    \"type\": \"event\",
    \"data\": {
        \"object\": {
            \"age\": \"18\",
               


        
6条回答
  •  孤城傲影
    2020-12-11 02:20

    If you are worried about the overhead because the object is deserialized to a JObject a and then serialized again (solution offered by @fero ) then you can try the following.

    Approach 1: Create your own custom JsonConverter and override ReadJson

    using(var jsonReader = new JsonTextReader(myTextReader))
    {
      while(jsonReader.Read()){
        if(jsonReader.TokenType.PropertyName=="SomeDesct")
        {
          //do what you want
        } 
      }
    }
    

    For more detail check the link Incremental JSON Parsing in C#

    Approach 2: Read the json string and apply string functions or regex function to get the desired string.

提交回复
热议问题