JSON数据解析代码示例

来源:互联网 发布:windows sever 2012 编辑:程序博客网 时间:2024/05/21 19:24
public static  StartAPKInfo parseStartAPKJson(InputStream inputStream){Log.i(TAG,  "parsePlaylistJson ");StartAPKInfo info = new StartAPKInfo();StringBuffer out = new StringBuffer();     byte[] b = new byte[4096];       try {for (int n; (n = inputStream.read(b)) != -1;) {  out.append(new String(b, 0, n)); }} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();return null;}     String str = out.toString();JSONObject obj = null;Iterator item = null;try {obj = new JSONObject(str);item = obj.keys();} catch (JSONException e1) {// TODO Auto-generated catch blocke1.printStackTrace();return null;}         while (item.hasNext()) {try {String key = (String) item.next();String s = obj.getString(key);if (key.equalsIgnoreCase("priority")) {info.priority = s;} else if (key.equalsIgnoreCase("category")){info.category= s;}else if (key.equalsIgnoreCase("source")){info.source = s;}else if (key.equalsIgnoreCase("source_package")){info.source_package = s;}else if (key.equalsIgnoreCase("video_tag")){info.video_tag = s;}else if (key.equalsIgnoreCase("title")){info.title = s;}else if (key.equalsIgnoreCase("img_url")){info.img_url = s;}else if (key.equalsIgnoreCase("callback_action")){info.callback_action = s;}else if (key.equalsIgnoreCase("callback_method")){info.callback_method = s;}else if (key.equalsIgnoreCase("callback_flag")){info.callback_flag = s;}else if (key.equalsIgnoreCase("callback_key")){info.callback_key = s;}else if (key.equalsIgnoreCase("callback_value")){info.callback_value = s;}} catch (JSONException e) {e.printStackTrace();}}return info;}

0 0
原创粉丝点击