Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My Json is 
{"headers":
["start_ip_int","end_ip_int","start_ip_oct","end_ip_oct","continent","country","country_code","country_cf","region","state","state_code","state_cf","city","city_cf","postal_code","area_code","time_zone","latitude","longitude","dma","msa","connection_type","line_speed","ip_routing_type","asn","sld","tld","organization","carrier","anonymizer_status","home","organization_type","naics_code","isic_code"]"
"results":{"120.74.45.21":["2856990464","2856990719","140.74.65.0","370.64.55.255","north america","united states","us","99","northeast","new york","ny","80","new york","61","10020","212","-5","40.75891","-73.97902","501","35620","tx","high","fixed","5049","","","dean witter financial services","morgan stanley & co.","","false","Finance","520000","K6400"
]
},"timeSpent":6}




I wanted to convert into model. I got the link where i can convert the json to appropriate model.



XML
public class RootObject
   {
       public List<string> headers { get; set; }
       public Results results { get; set; }
       public int timeSpent { get; set; }
   }

   public class Results
   {
       public IList<string> IpAddress { get; set; }
   }



But the problem is in json result
"results":{"120.74.45.21":

this is dynamic
so in Results class the property IpAddress is not mapping correctly.


JavaScriptSerializer js = new JavaScriptSerializer();
                            var objText = reader.ReadToEnd();
                            RootObject obj1 = new RootObject();

                            Results obj = new Results();
                            obj.IpAddress.Add(ipAddress);
                            obj1.results = obj;
                            obj1 = (RootObject)js.Deserialize(objText, typeof(RootObject));


in obj1 i am not getting the results. how can i fix this. Need your suggestion


otherwise kindly help me how i can achieve this
My requirement:
in json we have header and response
i want to map header with the the corresponding response.
in current case

"start_ip_int" :  2856990464
"end_ip_int"   :  2856990719
"start_ip_oct" :  140.74.65.0
"end_ip_oct"   :  370.64.55.255  
"continent"    :  north america
Posted
Updated 21-Mar-15 6:24am
v4

1 solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900