Answered by:
Decode JSON

Question
-
User-352524747 posted
How to decode this JSON, from yahoo:
{"query":{"count":4,"created":"2017-09-06T16:09:32Z","lang":"en-US","results":{"row":[{"symbol":"EURUSD=X","price":"1.1937","change":"+0.0025","percentchange":"+0.2132%"},{"symbol":"EURCHF=X","price":"1.1382","change":"+0.0000","percentchange":"+0.0044%"},{"symbol":"USDCHF=X","price":"0.9536","change":"-0.0019","percentchange":"-0.1989%"},{"symbol":"USDJPY=X","price":"108.7470","change":"-0.0030","percentchange":"-0.0028%"}]}}}
I want to read symbol, price, change and percentchange. While i use this code i get an error:
dynamic[] quotes = Json.Decode(marketdata.JsonData);
Error:
Unable to convert to "System.Object[]". Use Json.Decode<T> instead.
Wednesday, September 6, 2017 4:12 PM
Answers
-
User753101303 posted
Hi,
The array is deeper than that (query.result.rows). I would suggest to use copy/paste a json sample to http://json2csharp.com/ which will generate a C# class for this json. You can then use strogly typed code to get to whatever information you want...
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, September 6, 2017 4:50 PM
All replies
-
User753101303 posted
Hi,
The array is deeper than that (query.result.rows). I would suggest to use copy/paste a json sample to http://json2csharp.com/ which will generate a C# class for this json. You can then use strogly typed code to get to whatever information you want...
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, September 6, 2017 4:50 PM -
User347430248 posted
Hi dow7,
did you try to use Json.parse?
if not you can have a try.
function LaunchApp() { var data = '{"row":[{"symbol":"EURUSD=X","price":"1.1925","change":"+0.0004","percentchange":"+0.0344%"},{"symbol":"EURCHF=X","price":"1.1402","change":"+0.0002","percentchange":"+0.0219%"},{"symbol":"USDCHF=X","price":"0.9561","change":"+0.0002","percentchange":"+0.0230%"},{"symbol":"USDJPY=X","price":"109.0700","change":"-0.1860","percentchange":"-0.1702%"}]}'; var json = JSON.parse(data); alert(json["symbol"]); alert(json.price); alert(json.change); alert(json.percentchange); }
Reference:
Regards
Deepak
Thursday, September 7, 2017 7:37 AM -
User-352524747 posted
Now i have this c# class, can you please show me how to use it?
public class Row { public string symbol { get; set; } public string price { get; set; } public string change { get; set; } public string percentchange { get; set; } } public class Results { public List<Row> row { get; set; } } public class Query { public int count { get; set; } public string created { get; set; } public string lang { get; set; } public Results results { get; set; } } public class RootObject { public Query query { get; set; } }
Friday, September 8, 2017 9:33 PM