Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.accounts.OperationCanceledException;

public class Main {
    /**
     * get one JSONArray from a JSONArray according to tag and name pair
     * @param nameTag
     * @param name
     * @param jsonArray
     * @return
     * @throws JSONException
     */
    public static JSONArray getCorespondingJsonArray(String nameTag, String name, String arrayTag,
            JSONArray jsonArray) throws JSONException, OperationCanceledException {
        JSONObject org;
        String temp;
        for (int i = 0, size = jsonArray.length(); i < size; i++) {
            org = (JSONObject) jsonArray.opt(i);
            temp = org.getString(nameTag);
            if (temp.equals(name))
                return org.getJSONArray(arrayTag);
        }
        throw new OperationCanceledException("array not found");
    }
}