Menu
Forums
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Trending
What's new
New posts
New profile posts
Latest activity
Members
Current visitors
New profile posts
Search profile posts
Upgrades
Log in
Register
What's new
Search
Search
Search titles only
By:
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Menu
Log in
Register
Navigation
Install the app
Install
More options
Contact us
Close Menu
Forums
Software Development
Programming
Programming Q&A
[C# JSON] How do I get in
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="JayC" data-source="post: 466048" data-attributes="member: 36373"><p>Couple ways you could do this. You could do a JSON serializer, where you convert it into a class object, or you could do a LINQ from a parsed JSON.</p><p></p><p>So if you wanted to use a LINQ statement:</p><p></p><p>[CODE]JObject geographicalJSON = JObject.Parse(json); //json = Your string JSON</p><p></p><p>double Temperature = (double)geographicalJSON["main"]["temp"];[/CODE]</p><p></p><p>Or you could make a class structure and have it parse it out for you.</p><p></p><p>[CODE]public class GeographicalInfo</p><p>{</p><p> public Main Main {get; set;}</p><p>}</p><p></p><p>public class Main</p><p>{</p><p> public double Temp;</p><p> public double Feels_Like;</p><p> public double Temp_Min;</p><p> public double Temp_Max;</p><p> public double Pressure;</p><p> public double Humidity;</p><p>}</p><p></p><p>JavaScriptSerializer js = new JavaScriptSerializer();</p><p>GeographicalInfo [] geoInfo = js.Deserialize<GeographicalInfo[]>(geographicalJSON);</p><p>[/CODE]</p></blockquote><p></p>
[QUOTE="JayC, post: 466048, member: 36373"] Couple ways you could do this. You could do a JSON serializer, where you convert it into a class object, or you could do a LINQ from a parsed JSON. So if you wanted to use a LINQ statement: [CODE]JObject geographicalJSON = JObject.Parse(json); //json = Your string JSON double Temperature = (double)geographicalJSON["main"]["temp"];[/CODE] Or you could make a class structure and have it parse it out for you. [CODE]public class GeographicalInfo { public Main Main {get; set;} } public class Main { public double Temp; public double Feels_Like; public double Temp_Min; public double Temp_Max; public double Pressure; public double Humidity; } JavaScriptSerializer js = new JavaScriptSerializer(); GeographicalInfo [] geoInfo = js.Deserialize<GeographicalInfo[]>(geographicalJSON); [/CODE] [/QUOTE]
Insert quotes…
Verification
Post reply
Forums
Software Development
Programming
Programming Q&A
[C# JSON] How do I get in
Top