0

How to read a Json string with dynamic Node using c# ? I am not able to read the keys and sub nodes in the key.

      {
         "2030417": [{
          "country": "Malaysia",
          "push": 20543,
          "click": 752,
          "ctr": 3.66,
          "cpc": 0.03,
          "conversion": 0,
          "conversionrate": 0,
          "cpa": 0,
          "SOV%": "3.87"
         }],
         "2032769": [{
          "country": "India",
          "push": 10460,
          "click": 0,
          "ctr": 0,
          "cpc": 0.001,
          "conversion": 7,
          "conversionrate": 0.07,
          "cpa": 2.22,
          "SOV%": "0.28"
         }]
        }
3

1 Answer 1

1

You can either:

Use the dynamic object & call properties on the fly:

dynamic d = JObject.Parse("{number:1000, str:'string', array: [1,2,3,4,5,6]}");

Console.WriteLine(d.number);
Console.WriteLine(d.str);
Console.WriteLine(d.array.Count);

You can also iterate through different properties if needed:

JObject d = JObject.Parse("{\"2030417\":[{\"country\":\"Malaysia\",\"push\":20543,\"click\":752,\"ctr\":3.66,\"cpc\":0.03,\"conversion\":0,\"conversionrate\":0,\"cpa\":0,\"SOV%\":\"3.87\"}],\"2032769\":[{\"country\":\"India\",\"push\":10460,\"click\":0,\"ctr\":0,\"cpc\":0.001,\"conversion\":7,\"conversionrate\":0.07,\"cpa\":2.22,\"SOV%\":\"0.28\"}]}";);

var country = d["2030417"][0]["country"];
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.