Parsing Cryptocompare API Json data in C#

流过昼夜 提交于 2019-12-01 14:57:26

Create two objects. For example:

First:
public class JsonData {
public string time {get; set;}
public string high {get; set;}
etc...
}

Second:
public class DataRoot {
public string Response {get; set:}
public string Type {get; set:}
public bool Aggregated{get; set:}
public List<JsonData> Data{get; set:}
}

var root = JsonConvert.DeserializeObject<DataRoot>(YOUR JSON STRING HERE);
var rootData = root.Data;

Done...

Just use Json.Net:

https://www.nuget.org/packages/Newtonsoft.Json/

To install it using nuget use the following command in package console:

Install-Package Newtonsoft.Json

If you have a specific class that json can map to (for example JsonMapClass), you can use it like:

JsonMapClass json = JsonConvert.DeserializeObject<JsonMapClass>(jsonstring);

otherwise you may use dynamic object:

dynamic jsonjson = JsonConvert.DeserializeObject(jsonstring);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!