0

I have a Json object which returns json.

I call an api and convert into json object:

var returnJson = new JavaScriptSerializer().Deserialize(removeChar, targetType: null);

The results are:

{
  "Type": "Local",
  "results": {
    "A": 4.4023,
    "B": 1.6403,
    "C": 2.3457
}

how do I do literate through this json object and return just keys in array?

I unsure what goes in foreach loop:

foreach(var item in returnJson)
{
//get just keys.ToArray();
}

class file

public class BasicResults
    {
        public string Type { get; set; }
        public  Result results { get; set; }
    }

 public class Result
    {
      public double A { get; set; }
      public double B { get; set; }
      public double C { get; set; }
    }
}

I think this is in the right direction but can not target nested rate:

object[] getResults = returnJson.GetType()
                         .GetProperties()
                         .Select(p =>
                         {
                             object value = p.GetValue(results);
                             return value == null ? null : value.ToString();
                         })
                         .ToArray();
user3515765
  • 317
  • 2
  • 17

1 Answers1

0

Create a class like below

public class JsonData
{
    public string Type { get; set; }
    public Dictionary<string, string> Results { get; set; }
}

And the do the Deserialize

var returnJson = new JavaScriptSerializer().Deserialize<JsonData>(yourJsonString);

Then you can get the keys

 var keys = returnJson .Results.Keys;
Seminda
  • 1,745
  • 12
  • 15