Back to project page markj.
The source code is released under:
GNU Lesser General Public License
If you think the Android project markj listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.markjmind.mobile.api.android.json; //from ww w. j av a 2 s.c o m import java.util.ArrayList; import org.json.JSONObject; import android.util.Log; import com.markjmind.mobile.api.hub.Store; /** * * @author ??? * @email markjmind@gmail.com */ public class JwJOSNTreeArray extends JwJSONReader<Store>{ ArrayList<Store> data = new ArrayList<Store>(); Store root = new Store(); String rootName; String targetJsonName; public ArrayList<Store> getData(){ return data; } public JwJOSNTreeArray(String targetJsonName){ this.targetJsonName = targetJsonName; } public JwJOSNTreeArray(String rootName, String targetJsonName){ this.rootName = rootName; this.targetJsonName = targetJsonName; } @Override public void work(JSONObject json, String name, String parentName, Store parentResult) { if(parentResult==null){ root.add(name, json.optString(name)); return; } Store temp = (Store)parentResult.get(parentName); if(temp==null) return; temp.add(name, json.optString(name)); } @Override public Store startArrayWork(String name, Store parentResult) { if(parentResult==null){ parentResult= new Store(); } parentResult.add(name, new Store()); return parentResult; } @Override public void endArrayWork(String name, Store parentResult) { if(targetJsonName.equals(name)){ if(rootName!=null){ parentResult.add(rootName, root).clone(); }else{ parentResult.putAll(root); } data.add((Store)parentResult.clone()); parentResult.remove(name); } } }