Android 从Json中删除Json值

Android 从Json中删除Json值,android,json,Android,Json,我想从下面的json文件中删除json值 这是我的json对象: { "Approximation": { "name": "Approximation", "description": [ "Approximation", "Approximation", "Approximation" ], "video": [ "evideo/package1/maths/Approximation/349188_f2ba

我想从下面的json文件中删除json值

这是我的json对象:

{
  "Approximation": {
    "name": "Approximation",
    "description": [
      "Approximation",
      "Approximation",
      "Approximation"
    ],
    "video": [
      "evideo/package1/maths/Approximation/349188_f2ba28819a74355a456ef91d95451b71/349188_f2ba28819a74355a456ef91d95451b71/349188.mpd",
      "evideo/package3/maths/approxomation/396183_Approximation/396183_fcedf516e0f5c935d561d486058fa6e0/396183.mpd",
      "evideo/package2/maths/approxomation/387010_01approximation/387010_949440b1082fea19faa7dcb4aebf0b43/387010.mpd"
    ]
  }
}
这就是我正在尝试的

代码:

for (int i = 0; i < jsonArr.length(); i++) {

            JSONObject jsonObj = jsonArr.getJSONObject(i);
            jsonArr.remove(i);
            children = new ArrayList<ChildrenEvent>();
            et = new Events(jsonObj.optString("name"));
            ct = new ChildrenEvent(jsonObj.optString("description"));
            langs.add(et);
            children.add(ct);
  }
for(int i=0;i
JsonObject中有一个方法,即remove()。它将帮助您从jsonObject中删除任何键

使用以下命令:-

jsonObject.remove("key");

我不确定你在这里想要实现什么。您无需删除“近似”键即可获得数据

这就是解析这个JSON的方法

{
    "Approximation": {
        "name": "Approximation",
        "description": ["Approximation", "Approximation", "Approximation"],
        "video": ["evideo/package1/maths/Approximation/349188_f2ba28819a74355a456ef91d95451b71/349188_f2ba28819a74355a456ef91d95451b71/349188.mpd", "evideo/package3/maths/approxomation/396183_Approximation/396183_fcedf516e0f5c935d561d486058fa6e0/396183.mpd", "evideo/package2/maths/approxomation/387010_01approximation/387010_949440b1082fea19faa7dcb4aebf0b43/387010.mpd"]
    }
}
代码

JSONObject mainObj=新的JSONObject(json_字符串);
JSONObject appproxObj=mainObj.getJSONObject(“近似”);
//解析名称
String name=appproxObj.getString(“名称”);
et=新事件(名称);
langs.add(et);
//解析描述
JSONArray descriptions=appproxObj.getJSONArray(“description”);
children=newarraylist();
对于(int i=0;i

但是,如果您需要不带关键字“Approximation”的
JSON
,变量
appproxObj
有不带关键字的
JSON

那么您的问题是什么?我想从JSON中删除单词“Approximation”:并保存在approxobj的列表数组中,在哪个关键字下?在
JSON
{“Approximation”:{“name”:“Approximation”,“description”:[]}}中多次出现“Approximation”。当数组生成时
JSONObject mainObj = new JSONObject(json_string);
JSONObject appproxObj = mainObj.getJSONObject("Approximation");

// Parse name
String name = appproxObj.getString("name");
et = new Events(name);
langs.add(et);

// Parse descriptions
JSONArray descriptions = appproxObj.getJSONArray("description");
children = new ArrayList<ChildrenEvent>();
for (int i = 0; i < descriptions.length(); i++ ) {
    String description = descriptions.getString(i);
    ct = new ChildrenEvent(description);
    children.add(ct);       
}