Я пытаюсь прочитать json, используя java, который содержит данные меню, созданного Jquery плагином.
[
{
"text": "Home",
"href": "http://home.com",
"icon": "fas fa-home",
"target": "_top",
"title": "My Home"
},
{
"text": "Option1",
"href": "",
"icon": "fas fa-map-marker",
"target": "_self",
"title": "",
"children": [
{
"text": "Option1.1",
"href": "",
"icon": "fas fa-search",
"target": "_self",
"title": "",
"children": [
{
"text": "Option1.1.1",
"href": "",
"icon": "fas fa-plug",
"target": "_self",
"title": "",
"children": [
{
"text": "Option1.1.1.1",
"href": "",
"icon": "fas fa-filter",
"target": "_self",
"title": ""
}
]
}
]
},
{
"text": "Option1.2",
"icon": "fab fa-amazon-pay",
"href": "",
"target": "_self",
"title": "",
"children": [
{
"text": "Option1.2.1",
"icon": "empty",
"href": "",
"target": "_self",
"title": ""
}
]
}
]
},
{
"text": "Option2",
"icon": "fab fa-adversal",
"href": "",
"target": "_self",
"title": ""
}
]
Визуальное представление этого json будет похоже на
Children array is created dynamically. It can be in every object. Is there a way to read the children array which is inside of other children arrays ?
I'm using json-simple to read the json file and my current code is :
JSONParser parser = new JSONParser();
Object obj = parser.parse(new FileReader("C:\\Users\\ryuuk\\Desktop\\data.json"));
JSONArray jsonArray = (JSONArray) obj;
for (Iterator it = jsonArray.iterator(); it.hasNext();) {
JSONObject object = (JSONObject) it.next();
System.out.println(" "+ object.get (" текст ") +""); if (object.containsKey (" children ")) {System.out.println (" " ); JSONArray achil = (JSONArray) object.get ("дети"); for (int i = 0; i " + objectx.get ("текст") + "");} System.out.println ("");}}
Что выведет это:
<li><a href="#">Home</a>
<li><a href="#">Option1</a>
<ul>
<li><a href="#">Option1.1</a>
<li><a href="#">Option1.2</a>
</ul>
<li><a href="#">Option2</a>
введите описание изображения здесь
Как я могу прочитать эти дочерние массивы в Option1.1.1 ?