So for one, your expected JSON is malformed. Here is an example of your expected output
{ "country": {
"id" : "",
"name" : "",
"Lats" : "",
"Longs" : "",
"states" : [{
"id" : "",
"name" : "",
"Lats" : "",
"Longs" : "",
"citys" : {
"id" : "",
"name" : "",
"countryid" : "",
"stateid" : ""
}
},{
"id" : "",
"name" : "",
"Lats" : "",
"Longs" : "",
"citys" : {
"id" : "",
"name" : "",
"countryid" : "",
"stateid" : ""
}
}]
},
"country": {
"id" : "",
"name" : "",
"Lats" : "",
"Longs" : "",
"states" : [{
"id" : "",
"name" : "",
"Lats" : "",
"Longs" : "",
"citys" : {
"id" : "",
"name" : "",
"countryid" : "",
"stateid" : ""
}
},{
"id" : "",
"name" : "",
"Lats" : "",
"Longs" : "",
"citys" : {
"id" : "",
"name" : "",
"countryid" : "",
"stateid" : ""
}
}]
}
}
Then your class structure needs to be as follows
public class Citys
{
public string id { get; set; }
public string name { get; set; }
public string countryid { get; set; }
public string stateid { get; set; }
}
public class State
{
public string id { get; set; }
public string name { get; set; }
public string Lats { get; set; }
public string Longs { get; set; }
public Citys citys { get; set; }
}
public class Country
{
public string id { get; set; }
public string name { get; set; }
public string Lats { get; set; }
public string Longs { get; set; }
public List<state> states { get; set; }
}
public class RootObject
{
public Country country { get; set; }
}
</state>
I suggest you use JSON.NET library (newtonsoft) to serialize/deserialize your json.
For more info on JSON.net see this link:
Json.NET - Newtonsoft[
^]
From there you can just use the C# classes, assign values to whatever properties you want and when you are ready to convert that to JSON you just use
string json = JsonConvert.SerializeObject(model);