json.net - How to parse attribute in JsonConvert.DeserializeObject -


We have followed JSON output from an API.

We are using the following code in ASP.NET deserialize for a JSN response in a class:

  var j = JsonConvert.DeserializeObject & lt; Classname & gt; (reaction);   

While deserializing the following JSON, we are unable to get the attribute value.

  {"user": {"address": {"@CityName": "test", "$": "B4C99EB0-18E6-439F-882A-9E4A11E1FF75"}}}   

Please refer to us as the @ sitiname and $ attribute value.

We require the following output in the class:

  @CityName: Test $: B4C99EB0-18E6- 439F-882A-9E4A11E1FF75   < P> I'm getting element value, but I can not recognize the attribute value.  

Is there any way I can do that?

You can use [JsonProperty] to map non-standard JSON You can use the name of the property for properties in your class to create your classes like this:

  Root object of public class {public user user {get; Set; }} Public class user {public address address {get; Set; }} Public category address {[Jasonproperty ("@Centnam")] Public String CityName {Received; Set; } [Jasonproperty ("$")] Public String Guide {get; Set; }}   

Then deserialize like this:

  var obj = JsonConvert.DeserializeObject & lt; RootObject & gt; (reaction);    

Comments

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -