【发布时间】:2019-10-07 17:30:38
【问题描述】:
我正在尝试使用解析此 JSON。但是,我不知道如何解析“孩子”。我怎样才能将它映射到一个类?
我创建了一个类来解析“displayProperties”,但我不知道如何解析“children”
{
"displayProperties": {
"description": "",
"name": "Les Ténèbres",
"icon": "/common/destiny2_content/icons/39ba3c78d0ad06c0728374d591c65821.png",
"hasIcon": true
},
"originalIcon": "/common/destiny2_content/icons/39ba3c78d0ad06c0728374d591c65821.png",
"rootViewIcon": "/common/destiny2_content/icons/39ba3c78d0ad06c0728374d591c65821.png",
"nodeType": 1,
"scope": 1,
"objectiveHash": 4168198558,
"children": {
"presentationNodes": [
{
"presentationNodeHash": 655926402
},
{
"presentationNodeHash": 2082711113
},
{
"presentationNodeHash": 2474271317
}
],
"collectibles": [],
"records": []
}
}
abstract class DestinyObject(json : String) : JSONObject(json){
fun optDisplayProperties() : DisplayProperties{
val json_object : DisplayProperties = this.optJSONObject("displayProperties") as DisplayProperties
return json_object
}
}
class DisplayProperties(json : String) : JSONObject(json){
val name = this.optString("name")
val icon = this.optString("icon")
val description = this.optString("description")
}
【问题讨论】:
-
它是一个 JSONObject,里面有一个 JSONArrays
presentationNodes、collectibles和records。