How to get some values from a JSON string in C#?

前端 未结 4 2087
野的像风
野的像风 2020-11-29 22:14

I have a string and I want to get some values from it.

My strings seem like:

string1:

\"{\\r\\n   \\\"id\\\": \\\"100000280905615\\\",
 \\r\\         


        
4条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-29 22:28

    Following code is working for me.

    Usings:

    using System.IO;
    using System.Net;
    using Newtonsoft.Json.Linq;
    

    Code:

     using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
                    {
                        using (Stream responseStream = response.GetResponseStream())
                        {
                            using (StreamReader responseReader = new StreamReader(responseStream))
                            {
                                string json = responseReader.ReadToEnd();
                                string data = JObject.Parse(json)["id"].ToString();
                            }
                        }
                    }
    
    //json = {"kind": "ALL", "id": "1221455", "longUrl": "NewURL"}
    

提交回复
热议问题