gpt4 book ai didi

java - Android 中 JSON 将子树提取为字符串

转载 作者:行者123 更新时间:2023-12-02 02:44:02 26 4
gpt4 key购买 nike

我有以下 json 结构:

 "interpretation": {
"ComplexSearchRequest": {
"BoostLanguage": 0,
"Clauses": {
"MustClauses": [
{
"Match": {
"Attribute": "Channel",
"Operator": "None",
"Value": "n twenty four c h"
}
}
],
"MustNotClauses": []
},
"FilterLanguages": [],
"ItemFilters": [],
"MaxResults": 10
},
"GraphManagerRequestId": "baf28b69-0806-4725-9fb4-1d2acd1944ea",
"GraphManagerRequestLanguage": "de",
"Type": "Search"
},

如何提取整个节点“Clauses”并将其转换为字符串?输出应该是:

"Clauses": {
"MustClauses": [
{
"Match": {
"Attribute": "Channel",
"Operator": "None",
"Value": "n twenty four c h"
}
}
],
"MustNotClauses": []
},

需要一个最佳解决方案。

为了简单解析,我使用 JsonReader。

最佳答案

假设您有带有名称解释的 JSONObject,那么以下是获取子句的简单方法:

JSONObject complexSearchRequest = interpretation.getJSONObject("ComplexSearchRequest");
JSONObject clauses = complexSearchRequest.getJSONObject("Clauses");
Log.d("clauses",clauses.toString());

关于java - Android 中 JSON 将子树提取为字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44942817/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com