How to read a Json string with dynamic Node using c#? -


how read json string dynamic node using c# ? not able read keys , sub nodes in 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"          }]         } 

you can either:

use dynamic object & call properties on 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 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"]; 

Comments