2016-11-21 86 views
-5

我想从下面的json文件中删除json值。从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); 
    } 
+1

所以最新你的问题? – Fay007

+0

我想删除单词“Approximation”:从json并保存在应用程序的列表数组中 –

+0

下哪个键? “JSON”中出现了很多“近似”。 –

回答

0

中有一个JSONObject的方法,即是remove()。它将帮助你从jsonObject中删除任何键;

使用此: -

jsonObject.remove("key"); 
1

我不知道你正试图在这里实现什么。您不需要删除关键字“Approximation”来获取数据。

这就是你如何解析这个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 = 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);  
} 

不过如果你需要JSON无键 “逼近”,变量appproxObjJSON没有密钥。