Hi, I am using Newtonsoft.Json to parse my response coming from API call, title now I found simple kind of json response and able to parse very easily now I have some structure like this
"data": {
"error_warning": "",
"methods": {
"code1": {
"code": "code1",
"title": "Title code1",
"terms": "",
"sort_order": "5"
},
"code2": {
"code": "code2",
"title": "Title code2",
"terms": "",
"sort_order": "7"
}
},
"code": "",
"comment": "",
"agree": ""
}
How can I parse these kind of response using model
My previous models are like this
Response format :
{
"success": true,
"data": [
{
"category_id": "20",
"parent_id": "0",
"name": “Test”,
"image": "",
"original_image": "",
"filters": {
"filter_groups": []
},
"categories": null
},
{
"category_id": "18",
"parent_id": "0",
"name": “test1”,
"image": "",
"original_image": "",
"filters": {
"filter_groups": []
},
"categories": null
}
]
}
My model :
public class CategoryResponse
{
[JsonProperty("success")]
public string success { get; set; }
[JsonProperty("data")]
public List<Category> data { get; set; }
}
public class Category
{
[JsonProperty("id")]
public string id { get; set; }
[JsonProperty("category_id")]
public string category_id { get; set; }
[JsonProperty("parent_id")]
public string parent_id { get; set; }
[JsonProperty("name")]
public string name { get; set; }
[JsonProperty("image")]
public string image { get; set; }
[JsonProperty("original_image")]
public string original_image { get; set; }
[JsonProperty("categories")]
public string categories { get; set; }
}
I am able to parse the response like this
CategoryResponse resp = JsonConvert.DeserializeObject<CategoryResponse>(content);