且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Android中的JSON解码

更新时间:2023-02-23 12:36:39

这JSON可以是解析使用以下code。

this json can be parse using the following code.

str="<The Json>"
try {
                    JSONObject jObject=new JSONObject(str);
                    JSONArray menuObject = new JSONArray(jObject.getString("udeals"));

                    for (int i = 0; i<menuObject.length(); i++) {
                        System.out.println("length="+menuObject.length());
                        System.out.println("vName="+menuObject.getJSONObject(i)
                                .getString("vName").toString());
                        System.out.println("vAddress="+menuObject.getJSONObject(i).getString(
                                "vAddress").toString());
                        System.out.println("vState="+menuObject.getJSONObject(i)
                                .getString("vState").toString());
                        System.out.println("vZip="+menuObject.getJSONObject(i).getString(
                                "vZip").toString());
                        System.out.println("vCountry="+menuObject.getJSONObject(i)
                                .getString("vCountry").toString());
                        System.out.println("dealCategoryID="+menuObject.getJSONObject(i)
                                .getString("dealCategoryID").toString());
                        System.out.println("dealCaption="+menuObject.getJSONObject(i).getString(
                                "dealCaption").toString());
                        System.out.println("dealImage="+menuObject.getJSONObject(i)
                                .getString("dealImage").toString());
                        System.out.println("dealPrice="+menuObject.getJSONObject(i).getString(
                                "dealPrice").toString());
                        System.out.println("dealCost="+menuObject.getJSONObject(i)
                                .getString("dealCost").toString());
                        System.out.println("dealSave="+menuObject.getJSONObject(i).getString(
                                "dealSave").toString());
                        System.out.println("dealOfferRate="+menuObject.getJSONObject(i)
                                .getString("dealOfferRate").toString());
                        System.out.println("jsDeadLine="+menuObject.getJSONObject(i).getString(
                                "jsDeadLine").toString());
                        jsDeadLine=menuObject.getJSONObject(i).getString("jsDeadLine").toString();
                        JSONObject deadLine= new JSONObject(jsDeadLine);
                        String seconds = deadLine.getString("seconds");
                        String minutes = deadLine.getString("minutes");
                        String hours = deadLine.getString("hours");
                        String mday = deadLine.getString("mday");
                        String wday = deadLine.getString("wday");
                        String mon = deadLine.getString("mon");
                        String year = deadLine.getString("year");
                        String yday = deadLine.getString("yday");
                        String weekday = deadLine.getString("weekday");
                        String month = deadLine.getString("month");
                        System.out.println("seconds:"+seconds);
                        System.out.println("minutes:"+minutes);
                        System.out.println("hours:"+hours);



                        System.out.println("unlockedStamp="+menuObject.getJSONObject(i)
                                .getString("unlockedStamp").toString());

                        unlockedStamp=menuObject.getJSONObject(i).getString("unlockedStamp").toString();
                        JSONObject unlocked= new JSONObject(unlockedStamp);
                        String unlockedseconds = unlocked.getString("seconds");
                        String unlockedminutes = unlocked.getString("minutes");
                        String unlockedhours = unlocked.getString("hours");
                        String unlockedmday = unlocked.getString("mday");
                        String unlockedwday = unlocked.getString("wday");
                        String unlockedmon = unlocked.getString("mon");
                        String unlockedyear = unlocked.getString("year");
                        String unlockedyday = unlocked.getString("yday");
                        String unlockedweekday = unlocked.getString("weekday");
                        String unlockedmonth = unlocked.getString("month");
                        System.out.println("unlockedseconds:"+unlockedseconds);
                        System.out.println("unlockedminutes:"+unlockedminutes);
                        System.out.println("unlockedhours:"+unlockedhours);


                        System.out.println("description="+menuObject.getJSONObject(i).getString(
                                "description").toString());
                        System.out.println("id="+menuObject.getJSONObject(i)
                                .getString("id").toString());
                        System.out.println("dealurl="+menuObject.getJSONObject(i).getString(
                                "dealurl").toString());
                    }

                } catch (Exception e) {
                    e.printStackTrace();
                }



            }




    } catch (Exception e) {
        e.printStackTrace();
    }
    }