I have a JSON in this format:
{
"id1": {
"id": "183",
"contentname": "Title",
"content": "Some text",
"created": "2020-07-27"
},
"id2": {
"id": "182",
"contentname": "Title",
"content": "Some text",
"created": "2020-07-23"
},
"id3": {
"id": "180",
"contentname": "Title",
"content": "Some text",
"created": "2020-07-20"
},
"id4": {
"id": "179",
"contentname": "Title",
"content": "Some text",
"created": "2020-07-19"
}
}
I need to loop through it and add every item to new ArrayList:
ArrayList NewList = new ArrayList();
I need it so I can loop through my ArrayList later and retrieve any object I want. I tried using this website https://json2csharp.com/, but it returns this:
public class Id1 {
public string id { get; set; }
public string contentname { get; set; }
public string content { get; set; }
public string created { get; set; }
}
public class Id2 {
public string id { get; set; }
public string contentname { get; set; }
public string content { get; set; }
public string created { get; set; }
}
public class Root {
public Id1 id1 { get; set; }
public Id2 id2 { get; set; }
}
That is not very useful to me, because there will be 100+ different ids and more are added every day.
Is there any way to do what I want? It's for my Xamarin project, in Android I used Volley library and it works great, but I keep struggling in C#.
Thanks for help :)
EDIT: This is the PHP that generates my json:
<?php
class SeznamNovinekApi extends BaseApi
{
public function ToProcess($parametry)
{
$novinkyInfo = Database::SqlGetFetchAll("select id, pageid, contentname, content, created from mainpagesarticles where pageid = ? order by created desc", array('novinky'));
$i = 0;
foreach ($novinkyInfo as $info)
{
$i++;
$obj = ["id" => $info["id"], "pageid" => $info["pageid"], "contentname" => $info["contentname"], "content" => $info["content"], "created" => $info["created"]];
$this->json['id' . $i] = $obj;
}
}
}
?>