如何从同一个json文件解析两个不同的对象?

时间:2012-03-19 20:38:05

标签: java android json

如何解析同一个json文件中的两个不同对象,知道解析其中一个块会解析另一个,这意味着我只需要解析其中一个,这是我的代码:

try {

            time  = json1.getJSONObject(TAG_TIME);
            String Time2 = time.toString();

            deals = json1.getJSONObject(TAG_DEALS);
            final String plusinfo = deals.getString(TAG_PLUS_INFO);
            String title = deals.getString(TAG_TITLE);
            Integer retail = deals.getInt(TAG_RETAIL);
            String  nretail = Integer.toString(retail);
            Integer deal = deals.getInt(TAG_DEAL);
            String  ndeal = Integer.toString(deal);
            String duration = deals.getString(TAG_DURATION);
            String image = deals.getString(TAG_IMAGE_URL);
            String participant = deals.getString(TAG_PARTICIPANT);
            final String details = deals.getString(TAG_DETAILS);
            final String name = deals.getString(TAG_ADVERTISER_NAME);
            final String adress = deals.getString(TAG_ADVERTISER_ADDRESS);
            final String phone = deals.getString(TAG_ADVERTISSER_PHONE);
            /*String Time1 = deals.getString(TAG_DATE);
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Date date1 = new GregorianCalendar(0,0,0).getTime();
            Date date2 = new GregorianCalendar(0,0,0).getTime();
              try {  
                date1 = sdf.parse(Time1);
                date2 = sdf.parse(Time2);
              } catch (ParseException e) {
                e.printStackTrace();
              }

            final String precision = deals.getString(TAG_PRECISION);
            JSONArray c = deals.getJSONArray(TAG_PRECISION);
             ArrayList<String> arrays = new ArrayList<String>();
            for(int i = 0; i < c.length(); i++){
                 precision = c.getString(i);
                 arrays.add(precision);

            }
             HashMap<String, String> map = new HashMap<String, String>();


            map.put(TAG_TITLE, title);
            map.put(TAG_RETAIL, nretail);
            map.put(TAG_DEAL, ndeal);
            map.put(TAG_DURATION, duration);
            map.put(TAG_IMAGE_URL, image);
            map.put(TAG_PARTICIPANT, participant);
            map.put(TAG_SERVER_TIME, Time2);
            otherdeals.add(map); 

1 个答案:

答案 0 :(得分:0)

你是什么意思被封锁了?我不知道你发布的是什么问题。如果你想解析两个不同的JSON响应,要么启动两个后台线程(AsyncTask),要么只是一个接一个地解析它们