Get value from JSON with JSON.NET

后端 未结 3 1178
眼角桃花
眼角桃花 2020-12-01 13:47

I try to use http://www.codeplex.com/Json to extract values ​​from a json object.

I use imdbapi.com and they return json like this:

{\"Title\": \"Sta         


        
相关标签:
3条回答
  • 2020-12-01 14:28
    class TypeHere{
       string Name {get;set;}
    }
    
    TypeHere object = JsonConvert.DeserializeObject< TypeHere >(jsonString)
    
    // Ex. output 
    object.Name;
    
    0 讨论(0)
  • 2020-12-01 14:36

    This should help you http://james.newtonking.com/pages/json-net.aspx

    string json = @"{
        ""Name"": ""Apple"",
        ""Expiry"": new Date(1230422400000),
        ""Price"": 3.99,
        ""Sizes"": [
            ""Small"",
            ""Medium"",
            ""Large""
        ]
    }";
    
    JObject o = JObject.Parse(json);
    
    //This will be "Apple"
    string name = (string)o["Name"];
    
    0 讨论(0)
  • 2020-12-01 14:38

    JObject API documentation

    I believe you are interested in the .Item[key] collection that returns JTokens.

    Full Documentation

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