Can I LINQ a JSON?

前端 未结 3 444
谎友^
谎友^ 2020-11-29 04:28

This is the JSON I get from a request on .NET:

{
  \"id\": \"110355660738\", 
  \"picture\": {
    \"data\": {
      \"url\": \"https://fbcdn-profile-a.akama         


        
3条回答
  •  攒了一身酷
    2020-11-29 04:57

    I would not recommend LINQ. I would recommend a JSON library such as newtonsoft.json.

    So you can do this:

    string json = @"{
      ""Name"": ""Apple"",
      ""Expiry"": "2008-12-28T00:00:00",
      ""Price"": 3.99,
      ""Sizes"": [
        ""Small"",
        ""Medium"",
        ""Large""
      ]
    }";
    
    JObject o = JObject.Parse(json);
    
    string name = (string)o["Name"];
    
    // Apple
    JArray sizes = (JArray)o["Sizes"];
    string smallest = (string)sizes[0];
    
    // Small
    

    Note:- this code has been copied from the samples present on the project site http://james.newtonking.com/pages/json-net.aspx

提交回复
热议问题