0

I used to be loading data from Cryptocompare's API. This post got me what I wanted for Cryptocompare.

Parsing Cryptocompare API Json data in C#

However, I notice that this API is not bulletproof, it's not always returning an answer. So I want to use Kraken itself.

Now I am trying to deserialise the new JSON but this is not straightforward as Cryptocompare's JSON.

Here is an example JSON:

https://api.kraken.com/0/public/OHLC?pair=ETHUSD&interval=30

{"error":[],"result":{"XETHZUSD":[[1519236000,"825.94","846.00","825.94","845.00","835.62","858.29381033",708],[1519237800,"846.00","848.84","835.55","836.00","844.31","647.42747317",731],[1519239600,"836.00","841.09","830.76","834.89","835.13","1051.44905097",609],[1520530200,"706.24","710.43","701.90","704.59","707.70","1763.41692283",459]],"last":1520528400}}

I have not been able to deserialise this JSON.

Solved!!!

final solution:

    var Results_Exchange_Kraken = JsonConvert.DeserializeObject<DataRoot_Kraken>(Content_Exchange_Kraken);


    var price_data_kraken = Results_Exchange_Kraken.result.XETHZUSD;


    public class Kraken_Result
    {
        public List<List<object>> XETHZUSD { get; set; }
        public int last { get; set; }
    }

    public class DataRoot_Kraken
    {
        public List<object> error { get; set; }
        public Kraken_Result result { get; set; }
    }

Thank you! I'll bookmark the URL.

Yeahson
  • 139
  • 6
  • 1
    "I have not been able to deserialise this JSON.", and I don't even see an attempt from your side. Please read [ask] and either try for yourself or post what you have. Also, make it easier for us and run the JSON through a prettifier – Camilo Terevinto Mar 08 '18 at 19:12
  • Have you tried creating a model and then simply deserializing your JSON into the object of that model? – Sparsha Bhattarai Mar 08 '18 at 19:13
  • @camilo what i have does not work and might the the 20th attempt. I am not here to show what I have attempted (it was a LOT), this is not a school project, I am here to ask for help. – Yeahson Mar 08 '18 at 19:20

1 Answers1

2

Use this Model to de-serialise your data

public class Result
{
    public List<List<object>> XETHZUSD { get; set; }
    public int last { get; set; }
}

public class RootObject
{
    public List<object> error { get; set; }
    public Result result { get; set; }
}

Model Generated by Model Generator

Then use NewtonSoft for c# to de-serialise your data

E.g.

RootObject tmp = JsonConvert.DeserializeObject<RootObject>("JSON String here");

final solution:

    var Results_Exchange_Kraken = JsonConvert.DeserializeObject<DataRoot_Kraken>(Content_Exchange_Kraken);


    var price_data_kraken = Results_Exchange_Kraken.result.XETHZUSD;


    public class Kraken_Result
    {
        public List<List<object>> XETHZUSD { get; set; }
        public int last { get; set; }
    }

    public class DataRoot_Kraken
    {
        public List<object> error { get; set; }
        public Kraken_Result result { get; set; }
    }
Mihir Dave
  • 3,954
  • 1
  • 12
  • 28