canonical example by Tabnine
/** * Construct a UrlDevice Builder. * @param urlDevice the UrlDevice to clone. */ public Builder(UrlDevice urlDevice) { mNewId = urlDevice.mId; mNewUrl = urlDevice.mUrl; mNewExtraData = new JSONObject(urlDevice.mExtraData.toString()); }
JSONObject cred = new JSONObject(); JSONObject auth=new JSONObject(); JSONObject parent=new JSONObject(); cred.put("username","adm"); cred.put("password", "pwd"); auth.put("tenantName", "adm"); auth.put("passwordCredentials", cred.toString()); // <-- toString() parent.put("auth", auth.toString()); // <-- toString() OutputStreamWriter wr= new OutputStreamWriter(con.getOutputStream()); wr.write(parent.toString());
JSONObject jsonObj = null; try { jsonObj = XML.toJSONObject(sampleXml); } catch (JSONException e) { Log.e("JSON exception", e.getMessage()); e.printStackTrace(); } Log.d("XML", sampleXml); Log.d("JSON", jsonObj.toString());
try { JSONObject parent = new JSONObject(); JSONObject jsonObject = new JSONObject(); JSONArray jsonArray = new JSONArray(); jsonArray.put("lv1"); jsonArray.put("lv2"); jsonObject.put("mk1", "mv1"); jsonObject.put("mk2", jsonArray); parent.put("k2", jsonObject); Log.d("output", parent.toString(2)); } catch (JSONException e) { e.printStackTrace(); }
@Override public void print(JSONObject inputObject, PrintStream outputStream) throws Exception { LOG.info("JsonParser is parsing:" + inputObject.toString()); this.rewriteObject = outputStream == null; printer.println(inputObject.getString("cboInfo")); printer.println(); outputStream.println(printer.toString());
String mParameters[] = { "JAK", "1999" }; JSONObject mJson = new JSONObject(); try { mJson.put("name", "Katy"); JSONArray mJSONArray = new JSONArray(Arrays.asList(mParameters)); mJson.putOpt("parameters", mJSONArray); mJson.put("Age", 25); System.out.println("JSon::"+ mJson.toString()); } catch (JSONException e) { e.printStackTrace(); }
RequestQueue requestQueue = Volley.newRequestQueue(this); String URL = "http://..."; JSONObject jsonBody = new JSONObject(); jsonBody.put("Title", "Android Volley Demo"); jsonBody.put("Author", "BNK"); final String mRequestBody = jsonBody.toString(); e.printStackTrace();
public void actionPerformed(ActionEvent e) { String json = editTP.getText(); json = json.trim(); if (json.startsWith("{")) { JSONObject jsonObject = new JSONObject(json); String formatJson = jsonObject.toString(4); editTP.setText(formatJson); } else if (json.startsWith("[")) { JSONArray jsonArray = new JSONArray(json); String formatJson = jsonArray.toString(4); editTP.setText(formatJson); } } });
public TelegramApiRequestException(String message, JSONObject object) { super(message); apiResponse = object.getString(ERRORDESCRIPTIONFIELD); errorCode = object.getInt(ERRORCODEFIELD); if (object.has(PARAMETERSFIELD)) { try { parameters = OBJECT_MAPPER.readValue(object.getJSONObject(PARAMETERSFIELD).toString(), ResponseParameters.class); } catch (IOException e) { BotLogger.severe("APIEXCEPTION", e); } } }
"/admin/v1/journalcontexts/" + jobId, null, null); org.json.JSONObject jsonBody = new JSONObject(); result = getHttpRequest(jsonBody.toString(), agentUri, _sessionid); JSONObject response = new JSONObject(result); if(response != null ) { s_logger.debug("Job Status result for ["+jobId + "]:: " + result + " Tick and currentTime :" + System.currentTimeMillis() +" -" + startTick + "job cmd timeout :" +_nccCmdTimeout); String status = response.getJSONObject("journalcontext").getString("status").toUpperCase(); String message = response.getJSONObject("journalcontext").getString("message"); s_logger.debug("Job Status Progress Status ["+ jobId + "]:: " + status); switch(status) { s_logger.error(errMsg, e); } catch (JSONException e) { e.printStackTrace();
/** * Verfies if the signature of a JSONObject is valid * @param obj the JSONObject * @param key the public key of the signature issuer * @return true if the signature is valid * @throws SignatureException if the JSONObject does not have a signature or something with the JSONObject is bogus * @throws InvalidKeyException if the key is not valid (for example not RSA) */ public static boolean verify(JSONObject obj, PublicKey key) throws SignatureException, InvalidKeyException { if(!obj.has(signatureString)) throw new SignatureException("No signature supplied"); Signature signature; try { signature = Signature.getInstance("SHA256withRSA"); } catch (NoSuchAlgorithmException e) { return false; //does not happen } String sigString = obj.getString(signatureString); byte[] sig = Base64.getDecoder().decode(sigString); obj.remove(signatureString); signature.initVerify(key); signature.update(obj.toString().getBytes(StandardCharsets.UTF_8)); boolean res = signature.verify(sig); obj.put(signatureString, sigString); return res; }
GraphObject graphObject = response.getGraphObject(); JSONObject jsonObject = graphObject.getInnerJSONObject(); Log.d("data", jsonObject.toString(0)); Log.d("uid",friend.getString("uid")); Log.d("name", friend.getString("name")); Log.d("pic_square",friend.getString("pic_square")); e.printStackTrace();
public ArrayList<JsonBean> parseData(String result) {//Gson 解析 ArrayList<JsonBean> detail = new ArrayList<>(); try { JSONArray data = new JSONArray(result); Gson gson = new Gson(); for (int i = 0; i < data.length(); i++) { JsonBean entity = gson.fromJson(data.optJSONObject(i).toString(), JsonBean.class); detail.add(entity); } } catch (Exception e) { e.printStackTrace(); mHandler.sendEmptyMessage(MSG_LOAD_FAILED); } return detail; }
ArrayList<String> stringArray = new ArrayList<String>(); JSONArray jsonArray = new JSONArray(); for(int i = 0, count = jsonArray.length(); i< count; i++) { try { JSONObject jsonObject = jsonArray.getJSONObject(i); stringArray.add(jsonObject.toString()); } catch (JSONException e) { e.printStackTrace(); } }
String message; JSONObject json = new JSONObject(); json.put("name", "student"); JSONArray array = new JSONArray(); JSONObject item = new JSONObject(); item.put("information", "test"); item.put("id", 3); item.put("name", "course1"); array.put(item); json.put("course", array); message = json.toString(); // message // {"course":[{"id":3,"information":"test","name":"course1"}],"name":"student"}
JSONObject jsonParams = new JSONObject(); jsonParams.put("notes", "Test api support"); StringEntity entity = new StringEntity(jsonParams.toString()); client.post(context, restApiUrl, entity, "application/json", responseHandler);
public byte[] encode() { JSONObject var1 = new JSONObject(); try { if (!TextUtils.isEmpty(this.getContact_id())) { var1.put("contact_id", this.contact_id); } if (this.getJSONUserInfo() != null) { var1.put("bribery", this.getJSONUserInfo()); } } catch (JSONException var4) { var4.printStackTrace(); } try { return var1.toString().getBytes("UTF-8"); } catch (UnsupportedEncodingException var3) { var3.printStackTrace(); return null; } }
String json = {"phonetype":"N95","cat":"WP"}; try { JSONObject obj = new JSONObject(json); Log.d("My App", obj.toString()); } catch (Throwable t) { Log.e("My App", "Could not parse malformed JSON: \"" + json + "\""); }
/** * json 格式化 * * @param json * @return */ public static String jsonFormat(String json) { if (TextUtils.isEmpty(json)) { return "Empty/Null json content"; } String message; try { json = json.trim(); if (json.startsWith("{")) { JSONObject jsonObject = new JSONObject(json); message = jsonObject.toString(4); } else if (json.startsWith("[")) { JSONArray jsonArray = new JSONArray(json); message = jsonArray.toString(4); } else { message = json; } } catch (JSONException e) { message = json; } return message; }