-2

I am needing the first item in the array of object b in this json.

{
   "error":[],
   "result":{
      "XXRPXXBT":{
         "a":[
            "0.000084280",
            "123",
            "123.000"
         ],
         "b":[
            "0.000084120",
            "24263",
            "24263.000"
         ],
         "c":[
            "0.000084140",
            "772.40225814"
         ],
         "v":[
            "1002684.00590349",
            "1081301.61838716"
         ],
         "p":[
            "0.000085783",
            "0.000085799"
         ],
         "t":[
            731,
            866
         ],
         "l":[
            "0.000083420",
            "0.000083420"
         ],
         "h":[
            "0.000086610",
            "0.000086720"
         ],
         "o":"0.000086300"
      }
   }
}

Could someone please tell me how the class properties would look to get to that level. I have tried a json deserialization with a string for result but it fails on the convert.

I don't have to have all the values just the first item in the b array.

This is what I had done:

TestResponse deserializedKrakenResult = JsonConvert.DeserializeObject<TestResponse>(json);

public class TestResponse 
    {
        public string[] result { get; set; }
    }

and

public class TestResponse 
    {
        public object[] result { get; set; }
    }

and

public class TestResponse 
    {
        public string result { get; set; }
    }

These were done just to get it to parse.

Jed
  • 929
  • 2
  • 19
  • 32
  • 1
    Paste this JSON into http://json2csharp.com/ and see the generated classes. Go from there .... – HaukurHaf Jan 28 '19 at 14:33
  • @DavidG - what don't you understand about `"I have tried a json decentralization with a string for result but it fails on the convert."`? Obviously they're wide off the mark, but that's because they're (obviously) relatively new to coding. No need to be pedantic. –  Jan 28 '19 at 14:50
  • @JᴀʏMᴇᴇ Um, are you sure you meant to tag me? – DavidG Jan 28 '19 at 14:55
  • @DavidG - absolutely –  Jan 28 '19 at 15:10
  • @JᴀʏMᴇᴇ So how am I being pedantic? People need to demonstrate a level of effort, that's baked into the site rules. – DavidG Jan 28 '19 at 15:10
  • @DavidG - can you post the relevant rule please? There has been some level of effort, whether it's an adequate level or not is what's up for dispute. But to ask "have you tried anything yet?" appears to simply be ignorant OP's attempt with "json decentralization" (whatever that means). –  Jan 28 '19 at 15:20
  • @JᴀʏMᴇᴇ, The issue is that if you go in the search bar and type : `[c#] [json]` 80% of the last Week question can be solver by special past an Csharp .net . And many of them are upvoted. – xdtTransform Jan 28 '19 at 15:20
  • "What have you tried?", "show your code" etc. you see this on near enough every question these days. People can't wait to post it. But when you're addressing a question that's _obviously_ been asked by somebody new to coding you know that you're not going to get a full, comprehensive code example so maybe just try and help? Or, at the least, don't ask irrelevant questions - he's already said what he's tried. –  Jan 28 '19 at 15:21
  • @xdtTransform - yep, but that's not at all what I'm talking about. –  Jan 28 '19 at 15:21
  • @JᴀʏMᴇᴇ Look at the tooltip for the downvote button, it says *This question does not show any research effort; it is unclear or not useful (click again to undo)* – DavidG Jan 28 '19 at 15:24
  • In this question we have an XXRPXXBT, That look like a Dict>. We could have an ok question if Op talked about more about how he tryed. I read "I have tried a json decentralization with a string for result but it fails on the convert." as `JsonConvert.DeserializeObject(json);`. People have to show the code as there is no information in the question other that the json it self. – xdtTransform Jan 28 '19 at 15:24
  • @DavidG - Your response to `"I have tried a json decentralization..."` was `"Have you tried anything yet?"` It's not that tricky to see why I'm saying your comment was misplaced. –  Jan 28 '19 at 15:25
  • @JᴀʏMᴇᴇ But if they have not shown what they have tried, that sentence is meaningless. – DavidG Jan 28 '19 at 15:26
  • And it's [acceptable](https://meta.stackexchange.com/questions/122986/is-it-ok-to-leave-what-have-you-tried-comments) to leave those comments. – DavidG Jan 28 '19 at 15:26
  • @DavidG Sorry for the lack of details I did try a few types before posting – Jed Jan 28 '19 at 15:52
  • @Jed, We those information I can tell you that what you need should be `var root = JObject.Parse(input); var bValue = root["result"]["XXRPXXBT"]["b"].ToObject();` like https://rextester.com/JTSX23357 – xdtTransform Jan 28 '19 at 15:57
  • Possible duplicate of [deserialize part of json string (array) in c#](https://stackoverflow.com/questions/37335030/deserialize-part-of-json-string-array-in-c-sharp) – xdtTransform Jan 28 '19 at 15:58

1 Answers1

0
  • Open Visual Studio
  • Open Edit => Click Paste Special => Click Paste Json as Classes

enter image description here

Here is the result:

public class Rootobject
{
    public object[] error { get; set; }
    public Result result { get; set; }
}

public class Result
{
    public XXRPXXBT XXRPXXBT { get; set; }
}

public class XXRPXXBT
{
    public string[] a { get; set; }
    public string[] b { get; set; }
    public string[] c { get; set; }
    public string[] v { get; set; }
    public string[] p { get; set; }
    public int[] t { get; set; }
    public string[] l { get; set; }
    public string[] h { get; set; }
    public string o { get; set; }
}
Derviş Kayımbaşıoğlu
  • 28,492
  • 4
  • 50
  • 72