当前位置: 首页>>代码示例>>Java>>正文


Java JSONArray类代码示例

本文整理汇总了Java中org.json.JSONArray的典型用法代码示例。如果您正苦于以下问题:Java JSONArray类的具体用法?Java JSONArray怎么用?Java JSONArray使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


JSONArray类属于org.json包,在下文中一共展示了JSONArray类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: loadInBackground

import org.json.JSONArray; //导入依赖的package包/类
@Override
public List<RepositoryContentDataEntry> loadInBackground() {
    if (isRepoReady) {
        String uri = getContext().getString(R.string.url_repo_content, userName, repoName, path);
        FetchHTTPConnectionService fetchHTTPConnectionService = new FetchHTTPConnectionService(uri, getContext());
        HTTPConnectionResult result = fetchHTTPConnectionService.establishConnection();
        if (result == null) {
            return null;
        }

        try {
            JSONArray jsonArray = new JSONArray(result.getResult());
            return new RepoContentParser().parse(jsonArray);

        } catch (JSONException e) {
            Log.e(TAG, "Parse Error  ", e);
            Bundle bundle = new Bundle();
            bundle.putString(TAG, Utils.getStackTrace(e));
            firebaseAnalytics.logEvent(fbAEvent, bundle);
        }
    }
    return null;
}
 
开发者ID:OlgaKuklina,项目名称:GitJourney,代码行数:24,代码来源:RepoContentLoader.java

示例2: parseCity

import org.json.JSONArray; //导入依赖的package包/类
private void parseCity(String result) {
    try {
        JSONArray jArray = new JSONArray(result);

        for (int i = 0; i < jArray.length(); i++) {
            JSONObject jb = jArray.getJSONObject(i);
            String cityId = jb.getString("CITYID");
            String cityName = jb.getString("CITYNAME");
            cityNameId.put(cityName, cityId);
        }
        serializeCity(cityNameId);
        setAdapter();
    } catch (Exception e) {
        // TODO: handle exception
    }
}
 
开发者ID:mityung,项目名称:XERUNG,代码行数:17,代码来源:ProfileSetting.java

示例3: SupportedDownloads

import org.json.JSONArray; //导入依赖的package包/类
public SupportedDownloads(Context context) {
    try {
        String json = Utils.existFile(context.getFilesDir() + "/downloads.json") ?
                Utils.readFile(context.getFilesDir() + "/downloads.json", false) :
                Utils.readAssetFile(context, "downloads.json");
        JSONArray devices = new JSONArray(json);
        for (int i = 0; i < devices.length(); i++) {
            JSONObject device = devices.getJSONObject(i);
            JSONArray vendors = device.getJSONArray("vendor");
            for (int x = 0; x < vendors.length(); x++) {
                if (vendors.getString(x).equals(Device.getVendor())) {
                    JSONArray names = device.getJSONArray("device");
                    for (int y = 0; y < names.length(); y++) {
                        if (names.getString(y).equals(Device.getDeviceName())) {
                            mLink = device.getString("link");
                        }
                    }
                }
            }
        }
    } catch (JSONException e) {
        Utils.toast("Failed to read downloads.json " + e.getMessage(), context);
    }
}
 
开发者ID:AyushR1,项目名称:KernelAdiutor-Mod,代码行数:25,代码来源:SupportedDownloads.java

示例4: getBookmarks

import org.json.JSONArray; //导入依赖的package包/类
public static ArrayList<Bookmarks> getBookmarks() {
    String bookmarks = getString("maki_bookmarks", "[]");
    ArrayList<Bookmarks> listBookmarks = new ArrayList<>();
    try {
        JSONArray array = new JSONArray(bookmarks);
        for (int i = 0; i < array.length(); i++) {
            JSONObject ob = array.getJSONObject(i);
            Bookmarks bookmark = new Bookmarks();
            bookmark.setTitle(ob.getString("title"));
            bookmark.setUrl(ob.getString("url"));
            listBookmarks.add(bookmark);
        }
    } catch (JSONException e) {
        e.printStackTrace();
    }
    return listBookmarks;
}
 
开发者ID:sfilmak,项目名称:MakiLite,代码行数:18,代码来源:PreferencesUtility.java

示例5: placeJsonArrayRequest

import org.json.JSONArray; //导入依赖的package包/类
/**
 * @param apiTag         tag to uniquely distinguish Volley requests. Null is allowed
 * @param url            URL to fetch the string at
 * @param httpMethod     the request method to use (GET or POST)
 * @param params         A {@link JSONArray} to post with the request. Null is allowed and
 *                       indicates no parameters will be posted along with request.
 * @param headers        optional Http headers
 * @param serverCallback Listener to receive the String response
 */
public void placeJsonArrayRequest(@Nullable final String apiTag, String url, int httpMethod, @Nullable JSONArray params, final @Nullable HashMap<String, String> headers, final ServerCallback serverCallback) {

    Request request = new JsonArrayRequest(httpMethod, url, params, new Response.Listener<JSONArray>() {
        @Override
        public void onResponse(JSONArray response) {
            serverCallback.onAPIResponse(apiTag, response);
        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            serverCallback.onErrorResponse(apiTag, error);
        }
    }) {
        @Override
        public Map<String, String> getHeaders() throws AuthFailureError {
            return headers != null ? headers : super.getHeaders();
        }
    };

    request.setRetryPolicy(retryPolicy);

    addToRequestQueue(request);
}
 
开发者ID:ferozbaig96,项目名称:VolleySimple,代码行数:33,代码来源:VolleySimple.java

示例6: a

import org.json.JSONArray; //导入依赖的package包/类
public synchronized Fallback a(JSONObject jSONObject) {
    this.a = jSONObject.optString(c.a);
    this.n = jSONObject.getLong("ttl");
    this.l = jSONObject.getDouble("pct");
    this.i = jSONObject.getLong(DeviceInfo.TAG_TIMESTAMPS);
    this.d = jSONObject.optString("city");
    this.c = jSONObject.optString("prv");
    this.g = jSONObject.optString("cty");
    this.e = jSONObject.optString("isp");
    this.f = jSONObject.optString("ip");
    this.b = jSONObject.optString(com.alipay.sdk.cons.c.f);
    this.h = jSONObject.optString("xf");
    JSONArray jSONArray = jSONObject.getJSONArray("fbs");
    for (int i = 0; i < jSONArray.length(); i++) {
        a(new e().a(jSONArray.getJSONObject(i)));
    }
    return this;
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:19,代码来源:Fallback.java

示例7: getScores

import org.json.JSONArray; //导入依赖的package包/类
@Deprecated
public Score[] getScores(int beatMapID, GameMode gameMode, int amount, String userName) throws JSONException, MalformedURLException, IOException{
	if(amount > 100) amount = 100;
	if(amount < 1) amount = 1;
	StringBuilder sb = new StringBuilder();
	sb.append("https://osu.ppy.sh/api/get_scores?");
	sb.append("k=" + getAPIkey());
	sb.append("&b=" + beatMapID);
	sb.append("&m=" + gameMode.ordinal());
	sb.append("&limit=" + amount);
	sb.append("&u=" + userName);
	sb.append("&type=string");
	
	JSONArray scoresArray = new JSONArray(StringUtils.getStringFromWebsite(sb.toString()));
	Score[] scores = new Score[scoresArray.length()];
	for(int i = 0; i < scoresArray.length(); i++){
		scores[i] = new Score(scoresArray.getJSONObject(i));
	}
	return scores;
}
 
开发者ID:Kitt3120,项目名称:JOsu,代码行数:21,代码来源:JOsu.java

示例8: getByIds

import org.json.JSONArray; //导入依赖的package包/类
/**
 * Retorna a lista de boletos emitidos por códigos de pedidos
 * @param pedidos: Lista de códigos de pedidos os quais deseja retornar os boletos
 * @return String: Link contendo os boletos relacionados aos códigos de pedidos enviados
 */
public String getByIds(Set<String> pedidos) throws IOException, PJBankException {
    PJBankClient client = new PJBankClient(this.endPoint.concat("/transacoes/lotes"));
    HttpPost httpPost = client.getHttpPostClient();
    httpPost.addHeader("x-chave", this.getChave());

    JSONArray pedidosArray = new JSONArray(pedidos);

    JSONObject params = new JSONObject();
    params.put("pedido_numero", pedidosArray);

    httpPost.setEntity(new StringEntity(params.toString(), StandardCharsets.UTF_8));

    String response = EntityUtils.toString(client.doRequest(httpPost).getEntity());
    JSONObject responseObject = new JSONObject(response);

    return responseObject.getString("linkBoleto");
}
 
开发者ID:pjbank,项目名称:pjbank-java-sdk,代码行数:23,代码来源:BoletosManager.java

示例9: testCreateThumbnailInReadonlyMode

import org.json.JSONArray; //导入依赖的package包/类
public void testCreateThumbnailInReadonlyMode() throws Exception
{
    createUser(USER_ALFRESCO);
    AuthenticationUtil.setFullyAuthenticatedUser(USER_ALFRESCO);
    this.transactionService.setAllowWrite(false);
    
    // do pdfToSWF transformation in read-only
    if (this.contentService.getTransformer(MimetypeMap.MIMETYPE_PDF, MimetypeMap.MIMETYPE_FLASH) != null)
    {
        // in share creation of thumbnail for webpreview is forced
        String url = "/api/node/" + pdfNode.getStoreRef().getProtocol() + "/" + pdfNode.getStoreRef().getIdentifier() + "/" + pdfNode.getId() + "/content/thumbnails/webpreview?c=force";
        
        JSONObject tn = new JSONObject();
        tn.put("thumbnailName", "webpreview");
        
        sendRequest(new GetRequest(url), 200, USER_ALFRESCO);
    }
    
    this.transactionService.setAllowWrite(true);
    
    // Check getAll whilst we are here 
    Response getAllResp = sendRequest(new GetRequest(getThumbnailsURL(jpgNode)), 200);
    JSONArray getArr = new JSONArray(getAllResp.getContentAsString());
    assertNotNull(getArr);
    assertEquals(0, getArr.length());
}
 
开发者ID:Alfresco,项目名称:alfresco-remote-api,代码行数:27,代码来源:ThumbnailServiceTest.java

示例10: handleCountyResponse

import org.json.JSONArray; //导入依赖的package包/类
/**
 * 解析处理服务器返回的县级数据
 * @param response
 * @return
 */
public static boolean handleCountyResponse(String response,int cityId){
    if(!TextUtils.isEmpty(response)){
        try {
            JSONArray allCountys = new JSONArray(response);
            for (int i = 0; i < allCountys.length(); i++) {
                JSONObject countyJSONObject = allCountys.getJSONObject(i);
                County county = new County();
                county.setWeathreId(countyJSONObject.getString("weather_id"));
                county.setCountyName(countyJSONObject.getString("name"));
                county.setCityId(cityId);
                county.save();
            }
            return true;
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
    return false;
}
 
开发者ID:Jiabaokang,项目名称:JBKWeather,代码行数:25,代码来源:Utility.java

示例11: fromJSONObject

import org.json.JSONArray; //导入依赖的package包/类
public static StatisticsEvent fromJSONObject(JSONObject eventObject) {
    StatisticsEvent statisticsEvent = new StatisticsEvent();
    statisticsEvent.setKey(eventObject.optString(KEY));
    statisticsEvent.setValue(eventObject.optString(VALUE));
    statisticsEvent.setTime(eventObject.optString(TIME));
    statisticsEvent.setType(eventObject.optString(TYPE));
    try {
        JSONArray jsonArray = eventObject.optJSONArray(EXTENDS);
        if (jsonArray != null) {
            statisticsEvent.setExtendList(JsonUtil.toList(jsonArray.toString(), Extend.class));
        }
    } catch (JSONException e) {
        e.printStackTrace();
    }
    return statisticsEvent;
}
 
开发者ID:xingjiyuan,项目名称:AndroidStatisticsLib,代码行数:17,代码来源:StatisticsEvent.java

示例12: parseIatResult

import org.json.JSONArray; //导入依赖的package包/类
public static String parseIatResult(String json) {
		StringBuffer ret = new StringBuffer();
		try {
			JSONTokener tokener = new JSONTokener(json);
			JSONObject joResult = new JSONObject(tokener);

			JSONArray words = joResult.getJSONArray("ws");
			for (int i = 0; i < words.length(); i++) {
				// 转写结果词,默认使用第一个结果
				JSONArray items = words.getJSONObject(i).getJSONArray("cw");
				JSONObject obj = items.getJSONObject(0);
				ret.append(obj.getString("w"));
//				如果需要多候选结果,解析数组其他字段
//				for(int j = 0; j < items.length(); j++)
//				{
//					JSONObject obj = items.getJSONObject(j);
//					ret.append(obj.getString("w"));
//				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		} 
		return ret.toString();
	}
 
开发者ID:junchenChow,项目名称:exciting-app,代码行数:25,代码来源:JsonParser.java

示例13: loadInBackground

import org.json.JSONArray; //导入依赖的package包/类
@Override
public List<ReposDataEntry> loadInBackground() {
    String uri = getContext().getString(R.string.url_repos, page);
    FetchHTTPConnectionService fetchHTTPConnectionService = new FetchHTTPConnectionService(uri, getContext());
    HTTPConnectionResult result = fetchHTTPConnectionService.establishConnection();
    Log.v(TAG, "responseCode = " + result.getResponceCode());
    Log.v(TAG, "result = " + result.getResult());

    try {
        JSONArray jsonArray = new JSONArray(result.getResult());
        return new ReposParser().parse(jsonArray);

    } catch (JSONException e) {
        Log.e(TAG, "", e);
    }
    return null;
}
 
开发者ID:OlgaKuklina,项目名称:GitJourney,代码行数:18,代码来源:RepositoriesLoader.java

示例14: getBody

import org.json.JSONArray; //导入依赖的package包/类
@Override
protected byte[] getBody(Context context) {

    byte[] array = new byte[0];

    JSONObject body = new JSONObject();
    try {
        body.put("network_id", params.getNetworkId());
        body.put("zone_id", params.getZoneId());
        body.put("user_id", params.getUserId());
        List<String> stringList = new ArrayList<>(Arrays.asList(params.getKeywords()));
        body.put("keywords", new JSONArray(stringList));
        if(params.getWidth() != null)
            body.put("width", params.getWidth());
        if(params.getHeight() != null)
            body.put("height", params.getHeight());

        array =  body.toString().getBytes("UTF-8");
    } catch (JSONException | UnsupportedEncodingException e) {
        e.printStackTrace();

    }

    return  array;

}
 
开发者ID:AdyoOrg,项目名称:adyo-android,代码行数:27,代码来源:GetPlacementRequest.java

示例15: b

import org.json.JSONArray; //导入依赖的package包/类
public static void b(Context context, JSONObject jSONObject) {
    try {
        JSONArray jSONArray = new JSONArray();
        jSONArray.put(jSONObject);
        JSONObject jSONObject2 = new JSONObject();
        jSONObject2.put(z[6], jSONArray);
        if (a(jSONObject2, context)) {
            new StringBuilder(z[7]).append(jSONObject.toString());
            z.b();
            if (p.a(context, jSONObject2, true) == 200) {
                z.b();
            }
        }
    } catch (JSONException e) {
    } catch (Exception e2) {
    }
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:18,代码来源:ac.java


注:本文中的org.json.JSONArray类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。