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


Java JSONArray.get方法代码示例

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


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

示例1: DownloadInfo

import org.json.JSONArray; //导入方法依赖的package包/类
public DownloadInfo(String name, String json) {
    try {
        JSONObject jsonObject = new JSONObject(json);
        this.inputName = name;


        this.name = jsonObject.getString("fullName");
        this.bday = jsonObject.getString("bday");
        this.mail = jsonObject.getString("email");
        this.phone = jsonObject.getString("phone");
        JSONArray jsonArray = jsonObject.getJSONArray("skills");
        skills = new String[jsonArray.length()];

        for (int i = 0; i < jsonArray.length(); i++) {
            skills[i] = (String) jsonArray.get(i);
        }
    } catch (JSONException e) {
        e.printStackTrace();
    }
}
 
开发者ID:Jugendhackt,项目名称:SocialPaka,代码行数:21,代码来源:DownloadInfo.java

示例2: toSet

import org.json.JSONArray; //导入方法依赖的package包/类
/**
 * This is used in Put command this method uses HashSet as default implementation
 * 
 * @param value
 * @param parameterType
 * @return setValue
 * @throws GfJsonException
 */
@SuppressWarnings({"rawtypes", "unchecked"})
private static Object toSet(Object value, Class<?> parameterType) throws GfJsonException {
  try {
    JSONArray array = (JSONArray) value;
    Set set = new HashSet();
    for (int i = 0; i < array.length(); i++) {
      Object element = array.get(i);
      if (isPrimitiveOrWrapper(element.getClass())) {
        set.add(element);
      } else
        throw new GfJsonException(
            "Only primitive types are supported in set type for input commands");
    }
    return set;
  } catch (JSONException e) {
    throw new GfJsonException(e);
  }
}
 
开发者ID:ampool,项目名称:monarch,代码行数:27,代码来源:JsonUtil.java

示例3: getUserFilesTree

import org.json.JSONArray; //导入方法依赖的package包/类
public static void getUserFilesTree(JSONObject jsonObject, JSONObject jsonObject2,
                                    Set<Long> fileIdSet) throws Exception {
    if (jsonObject.getInt("folder") == 1) {
        JSONArray jsonArray = jsonObject.getJSONArray("children");
        for (int i=0; i<jsonArray.length(); i++) {
            JSONObject origin = (JSONObject) jsonArray.get(i);
            if (origin.getInt("folder") == 0) {
                if (!fileIdSet.contains(origin.getLong("id"))) continue;
            }

            JSONObject jsonObject1 = new JSONObject();
            // copy..
            copyNode(origin, jsonObject1);
            jsonObject2.getJSONArray("children").put(jsonObject1);
            getUserFilesTree(origin, jsonObject1, fileIdSet);
        }

    }
}
 
开发者ID:thomas-young-2013,项目名称:wherehowsX,代码行数:20,代码来源:TreeFilter.java

示例4: MerkleTree

import org.json.JSONArray; //导入方法依赖的package包/类
/**
 * Create MerkleTree instance from a JSON representation
 *
 * @param json
 */
public MerkleTree(final JSONObject json) {
    final JSONArray jArray = json.getJSONArray("nodes");
    final JSONArray nodeIds = json.getJSONArray("nodeIds");
    final List<Node> nodes = new ArrayList<>();
    for (int i = 0; i < jArray.length(); i++) {
        final Object type = jArray.get(i);
        if (type instanceof JSONObject) {
            nodes.add(new Node((JSONObject) type));
        } else {
            throw new IllegalArgumentException("Unknow object in nodeArray ! " + type);
        }
    }
    // Connect nodes (parents and children were assigned to null because
    // json cannot handle objects with recursive definition
    for (int i = 0; i < nodeIds.length(); i += 2) {
        final Integer nodeId = i / 2;
        if ((Integer) nodeIds.get(i) != NO_CHILD) {
            nodes.get((Integer) nodeIds.getInt(i)).setParent(nodes.get(nodeId));
        }
        if ((Integer) nodeIds.get(i + 1) != NO_CHILD) {
            nodes.get((Integer) nodeIds.getInt(i + 1)).setParent(nodes.get(nodeId));
        }
    }
    root = nodes.get(0);
}
 
开发者ID:StanIsAdmin,项目名称:CrashCoin,代码行数:31,代码来源:MerkleTree.java

示例5: fetchRancherStacks

import org.json.JSONArray; //导入方法依赖的package包/类
/** fetch stacks from server **/
public ArrayList<RancherStack> fetchRancherStacks() throws UnirestException, AuthenticationException {
    HttpResponse<JsonNode> jsonResponse = null;

    if(apiPw != null && apiUser != null)
        jsonResponse = Unirest.get(apiURL).header("accept", "application/json").basicAuth(apiUser,apiPw).asJson();

    if(apiUser == null && apiPw == null)
        jsonResponse = Unirest.get(apiURL).header("accept", "application/json").asJson();

    if (jsonResponse != null) {
        if(jsonResponse.getStatus() == 401)
            throw new AuthenticationException("Rancher Server returned 401 (Unauthorized).");

        JSONArray jsonStacks = jsonResponse.getBody().getObject().getJSONArray("data");

        for(int i = 0; i<jsonStacks.length();i++){
            JSONObject rStack = (JSONObject) jsonStacks.get(i);
            RancherStack newStack = new RancherStack();
            newStack.setId(rStack.getString("id"));
            newStack.setName(rStack.getString("name"));
            this.stacks.add(newStack);
        }
    }else{
        System.err.println("Could not fetch stacks from server.");
        return null;
    }
    return this.stacks;
}
 
开发者ID:Gmentsik,项目名称:ranch2git,代码行数:30,代码来源:RancherInstance.java

示例6: jsonArrayToWritableArray

import org.json.JSONArray; //导入方法依赖的package包/类
public static WritableArray jsonArrayToWritableArray(JSONArray jsonArray) {
    WritableArray writableArray = new WritableNativeArray();

    try {
        if (jsonArray == null) {
            return null;
        }

        if (jsonArray.length() <= 0) {
            return null;
        }

        for (int i = 0 ; i < jsonArray.length(); i++) {
            Object value = jsonArray.get(i);
            if (value == null) {
                writableArray.pushNull();
            } else if (value instanceof Boolean) {
                writableArray.pushBoolean((Boolean) value);
            } else if (value instanceof Integer) {
                writableArray.pushInt((Integer) value);
            } else if (value instanceof Double) {
                writableArray.pushDouble((Double) value);
            } else if (value instanceof String) {
                writableArray.pushString((String) value);
            } else if (value instanceof JSONObject) {
                writableArray.pushMap(jsonToWritableMap((JSONObject) value));
            } else if (value instanceof JSONArray) {
                writableArray.pushArray(jsonArrayToWritableArray((JSONArray) value));
            }
        }
    } catch (JSONException e) {
        // Do nothing and fail silently
    }

    return writableArray;
}
 
开发者ID:ccm-innovation,项目名称:react-native-twilio-chat,代码行数:37,代码来源:RCTConvert.java

示例7: parse

import org.json.JSONArray; //导入方法依赖的package包/类
public Object parse(Object data) throws Exception {
    if (data == null) {
        return null;
    }
    JSONObject o = new JSONObject((String) data);
    Log.i("LetvFeedbackParser", o.getString("code"));
    if (!o.getString("code").equals(CODE_VALUES.SUCCESS)) {
        return null;
    }
    Object cmdinfo = new Cmdinfo();
    if (!o.has(ShareRequestParam.RESP_UPLOAD_PIC_PARAM_DATA)) {
        return cmdinfo;
    }
    JSONObject mdata = o.getJSONObject(ShareRequestParam.RESP_UPLOAD_PIC_PARAM_DATA);
    Log.i("LetvFeedbackParser", "HttpFeedbackRequest:mdata=" + o);
    cmdinfo.setFbCode(mdata.getString("fbCode"));
    cmdinfo.setFbId(Long.valueOf(mdata.getLong("fbId")));
    cmdinfo.setUpPeriod(mdata.getInt("upPeriod"));
    cmdinfo.setEndTime(Long.valueOf(mdata.getLong("endTime")));
    JSONArray cmdArray = mdata.getJSONArray("cmdAry");
    Log.i("LetvFeedbackParser", "HttpFeedbackRequest:cmdArray=" + cmdArray);
    if (cmdArray != null) {
        Order order = new Order();
        for (int i = 0; i < cmdArray.length(); i++) {
            JSONObject myJson = (JSONObject) cmdArray.get(i);
            Tag tag = new Tag();
            tag.setCmdId(Long.valueOf(myJson.getLong("cmdId")));
            tag.setUpType(myJson.getInt("upType"));
            tag.setCmdType(myJson.getInt("cmdType"));
            tag.setCmdParam(myJson.getString("cmdParam"));
            tag.setCmdUrl(myJson.getString("cmdUrl"));
            order.add(tag);
        }
        Log.i("LetvFeedbackParser", "myorder" + order);
        cmdinfo.setCmdAry(order);
        return cmdinfo;
    }
    cmdinfo.setCmdAry(null);
    return cmdinfo;
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:41,代码来源:LetvFeedbackInitParser.java

示例8: parse

import org.json.JSONArray; //导入方法依赖的package包/类
private void parse(JSONObject json) {

		if (!json.isNull("multicast_id")) {
			mMulticastId = (Long) json.getLong("multicast_id");
		}
		if (!json.isNull("success")) {
			mSuccess = (Integer) json.getInt("success");
		}
		if (!json.isNull("failure")) {
			mFailure = (Integer) json.getInt("failure");
		}
		if (!json.isNull("canonical_ids")) {
			mCanonicalIds = (Integer) json.getInt("canonical_ids");
		}

		JSONArray results = (JSONArray) getn(json, "results");

		if (results != null) {
			for (int i = 0; i < results.length(); i++) {

				if (mResultList == null) {
					mResultList = new ArrayList<FcmResult>();
				}

				FcmResult rslt = new FcmResult();
				mResultList.add(rslt);

				JSONObject obj = (JSONObject) results.get(i);
				if (!obj.isNull("message_id")) {
					rslt.messageId = (String) getn(obj, "message_id");
				}
				if (!obj.isNull("error")) {
					rslt.error = (String) getn(obj, "error");
				}
				if (!obj.isNull("registration_id")) {
					rslt.registrationId = (String) getn(obj, "registration_id");
				}
			}
		}
	}
 
开发者ID:riversun,项目名称:java-firebase-fcm-client,代码行数:41,代码来源:FcmResponse.java

示例9: getSiteMembers

import org.json.JSONArray; //导入方法依赖的package包/类
protected Set<String> getSiteMembers(RepoCtx ctx, String siteId, String tenantDomain) throws Exception
{
    // note: tenant domain ignored her - it should already be part of the siteId
    Set<String> members = new HashSet<String>();
    if ((siteId != null) && (siteId.length() != 0))
    {
        StringBuffer sbUrl = new StringBuffer();
        sbUrl.append(ctx.getRepoEndPoint()).
              append(URL_SERVICE_SITES).append("/").append(siteId).append(URL_MEMBERSHIPS);
        
        String jsonArrayResult = callWebScript(sbUrl.toString(), ctx.getTicket());
        if ((jsonArrayResult != null) && (jsonArrayResult.length() != 0))
        {
            JSONArray ja = new JSONArray(jsonArrayResult);
            for (int i = 0; i < ja.length(); i++)
            {
                JSONObject member = (JSONObject)ja.get(i);
                JSONObject person = (JSONObject)member.getJSONObject("person");
                
                String userName = person.getString("userName");
                if (! ctx.isUserNamesAreCaseSensitive())
                {
                    userName = userName.toLowerCase();
                }
                members.add(userName);
            }
        }
    }
    
    return members;
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:32,代码来源:FeedTaskProcessor.java

示例10: parse

import org.json.JSONArray; //导入方法依赖的package包/类
@Override
protected boolean parse(JSONObject object) throws JSONException {
    mErrorCode = object.getInt("error");
    if (mErrorCode == 0) {
        JSONArray results = object.getJSONArray("results");
        JSONObject summary = (JSONObject) results.get(0);
        mCurrentCity = summary.getString("currentCity");
        mPM25 = summary.getInt("pm25");
        JSONArray weathers = summary.getJSONArray("weather_data");
        todayWeather = new Weather();
        JSONObject todayJsonObject = (JSONObject) weathers.get(0);
        todayWeather.parse(todayJsonObject);
    }
    return true;
}
 
开发者ID:socoolby,项目名称:CoolClock,代码行数:16,代码来源:WeatherResponse.java

示例11: parseArrayOfDatabaseEntities

import org.json.JSONArray; //导入方法依赖的package包/类
/**
 * Saves and associate these database entities to this object
 *
 * @param value database entities to process
 * @param type  type of the database entities
 * @return new list of database entities
 * @throws JSONException the exception
 */
private List<Object> parseArrayOfDatabaseEntities(final JSONArray value, final Class type) throws JSONException {
    final List<Object> elements = new ArrayList<>();

    for (Integer i = 0; i < value.length(); i++) {
        if (!value.isNull(i)) {
            final JSONObject data = (JSONObject) value.get(i);
            elements.add(parseBaseEntity(data, type));
        }
    }
    return elements;
}
 
开发者ID:mhaddon,项目名称:Sound.je,代码行数:20,代码来源:FormParse.java

示例12: convertJsonToArray

import org.json.JSONArray; //导入方法依赖的package包/类
private static WritableArray convertJsonToArray(JSONArray jsonArray) throws JSONException {
  WritableArray array = new WritableNativeArray();

  for (int i = 0; i < jsonArray.length(); i++) {
    Object value = jsonArray.get(i);
    if (value instanceof JSONObject) {
      array.pushMap(convertJsonToMap((JSONObject) value));
    } else if (value instanceof JSONArray) {
      array.pushArray(convertJsonToArray((JSONArray) value));
    } else if (value instanceof Boolean) {
      array.pushBoolean((Boolean) value);
    } else if (value instanceof Integer) {
      array.pushInt((Integer) value);
    } else if (value instanceof Double) {
      array.pushDouble((Double) value);
    } else if (value instanceof String) {
      array.pushString((String) value);
    } else {
      array.pushString(value.toString());
    }
  }
  return array;
}
 
开发者ID:humaniq,项目名称:react-native-android-library-humaniq-api,代码行数:24,代码来源:ModelConverterUtils.java

示例13: parseJsonFeed

import org.json.JSONArray; //导入方法依赖的package包/类
/**
 * Parsing json reponse and passing the data to feed view list adapter
 * */
private void parseJsonFeed(JSONObject response) {
    try {
        JSONArray feedArray = response.getJSONArray("feed");

        for (int i = 0; i < feedArray.length(); i++) {
            JSONObject feedObj = (JSONObject) feedArray.get(i);

            FeedItem item = new FeedItem();
            item.setId(feedObj.getInt("id"));
            item.setName(feedObj.getString("name"));

            // Image might be null sometimes
            String image = feedObj.isNull("image") ? null : feedObj
                    .getString("image");
            item.setImge(image);
            item.setStatus(feedObj.getString("status"));
            item.setProfilePic(feedObj.getString("profilePic"));
            item.setTimeStamp(feedObj.getString("timeStamp"));

            // url might be null sometimes
            String feedUrl = feedObj.isNull("url") ? null : feedObj
                    .getString("url");
            item.setUrl(feedUrl);

            feedItems.add(item);
        }

        // notify data changes to list adapater
        listAdapter.notifyDataSetChanged();
    } catch (JSONException e) {
        e.printStackTrace();
    }
}
 
开发者ID:cdc03819,项目名称:BrewBook,代码行数:37,代码来源:trending.java

示例14: docTedTransfer

import org.json.JSONArray; //导入方法依赖的package包/类
/**
 * Realiza várias transferências via DOC/TED a partir da Conta Digital
 * @param transferencias: Transferências à serem executadas
 * @return List<ResponseTransferencia>: Lista com retorno de cada transferência do lote
 */
public List<ResponseTransferencia> docTedTransfer(List<TransacaoTransferencia> transferencias) throws IOException, ParseException, PJBankException {
    if (transferencias.size() == 1)
        return new ArrayList<>(Arrays.asList(this.docTedTransfer(transferencias.get(0))));

    PJBankClient client = new PJBankClient(this.endPoint.concat("/transacoes"));
    HttpPost httpPost = client.getHttpPostClient();
    httpPost.addHeader("x-chave-conta", this.chave);
    DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");

    JSONArray despesasArray = new JSONArray();

    for (TransacaoTransferencia transacaoTransferencia : transferencias) {
        JSONObject despesaObject = new JSONObject();
        despesaObject.put("data_pagamento", dateFormat.format(transacaoTransferencia.getDataPagamento()));
        despesaObject.put("data_vencimento", dateFormat.format(transacaoTransferencia.getDataVencimento()));
        despesaObject.put("valor", transacaoTransferencia.getValor());
        despesaObject.put("banco_favorecido", transacaoTransferencia.getBancoFavorecido());
        despesaObject.put("conta_favorecido", transacaoTransferencia.getContaFavorecido());
        despesaObject.put("agencia_favorecido", transacaoTransferencia.getAgenciaFavorecido());
        despesaObject.put("nome_favorecido", transacaoTransferencia.getNomeFavorecido());
        despesaObject.put("cnpj_favorecido", transacaoTransferencia.getCnpjFavorecido());
        despesaObject.put("identificador", transacaoTransferencia.getIdentificador());
        despesaObject.put("descricao", transacaoTransferencia.getDescricao());
        despesaObject.put("solicitante", transacaoTransferencia.getSolicitante());
        despesaObject.put("tipo_conta_favorecido", transacaoTransferencia.getTipoContaFavorecido().getName());

        despesasArray.put(despesaObject);
    }

    JSONObject params = new JSONObject();
    params.put("lote", despesasArray);

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

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

    JSONArray responseArray = new JSONArray(response);
    List<ResponseTransferencia> responsesTransferencias = new ArrayList<>();

    for(int i = 0; i < responseArray.length(); i++) {
        JSONObject object = (JSONObject) responseArray.get(i);

        ResponseTransferencia responseTransferencia = new ResponseTransferencia();
        responseTransferencia.setIdentificador(object.getString("identificador"));
        responseTransferencia.setIdOperacao(object.getString("id_operacao"));

        String dataPagamento = object.getString("data_pagamento");
        if (!StringUtils.isBlank(dataPagamento))
            responseTransferencia.setDataPagamento(dateFormat.parse(dataPagamento));

        responseTransferencia.setStatus(object.getInt("status"));
        responseTransferencia.setMessage(object.getString("msg"));

        responsesTransferencias.add(responseTransferencia);
    }

    return responsesTransferencias;
}
 
开发者ID:pjbank,项目名称:pjbank-java-sdk,代码行数:64,代码来源:ContaDigitalManager.java

示例15: onEvent

import org.json.JSONArray; //导入方法依赖的package包/类
@Subscribe(sticky = true,threadMode = ThreadMode.MAIN)
public void onEvent(BaseEvents.sendParamsToOnlineConsultingFragment event) throws JSONException {
    // UI updates must run on MainThread

    if (event == BaseEvents.sendParamsToOnlineConsultingFragment.ShowDemo) {
        Log.e("eventbus","eventbus");
        listTopicsData.clear();
       JSONArray data=new JSONArray(event.getObject().toString());
        String title,created_at,topic_category_name,content;int status,replies_count;

        for (int i = 0; i <data.length() ; i++) {
            JSONObject o= (JSONObject) data.get(i);
            if(MedicationHelper.isNullOrEmpty(o.getString("title")))
            {
                title="";
            }else {
                title =o.getString("title");
            }
            if(MedicationHelper.isNullOrEmpty(o.getString("created_at")))
            {
                created_at="";
            }else {
                created_at =o.getString("created_at");
            }
            if(MedicationHelper.isNullOrEmpty(o.getString("topic_category_name")))
            {
                topic_category_name="";
            }else {
                topic_category_name =o.getString("topic_category_name");
            }
            if(MedicationHelper.isNullOrEmpty(o.getString("content")))
            {
                content="";
            }else {
                content =o.getString("content");
            }

            status = o.getInt("status");


            replies_count =o.getInt("replies_count");

            listTopicsData.add(new TopicsData(title,created_at,topic_category_name,content,status,replies_count));
            commonAdapter.notifyDataSetChanged();
    }

}
}
 
开发者ID:MedicationReminder,项目名称:MedicationReminder,代码行数:49,代码来源:FragmentTabOnLineConuslting.java


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