JSONParser jParser = new JSONParser(); String json = jParser.getJSONFromUrl(url);
private Object parse(String s) { try { JSONParser parser = new JSONParser(); return parser.parse(s); } catch (Exception e) { throw new IllegalStateException("Invalid JSON: " + s, e); } }
JSONObject json = (JSONObject)new JSONParser().parse("{\"name\":\"MyNode\", \"width\":200, \"height\":100}"); System.out.println("name=" + json.get("name")); System.out.println("width=" + json.get("width"));
JSONParser parser = new JSONParser(); Object obj = parser.parse(new FileReader("simple.json")); JSONObject jsonObject = (JSONObject) obj; for(Iterator iterator = jsonObject.keySet().iterator(); iterator.hasNext();) { String key = (String) iterator.next(); System.out.println(jsonObject.get(key)); }
@Override public List<String> getSSTFilesFromMeta(Path localMetaPath) throws Exception { if (localMetaPath.toFile().isDirectory() || !localMetaPath.toFile().exists()) throw new InvalidPathException( localMetaPath.toString(), "Input path is either directory or do not exist"); List<String> result = new ArrayList<>(); JSONParser jsonParser = new JSONParser(); org.json.simple.JSONArray fileList = (org.json.simple.JSONArray) jsonParser.parse(new FileReader(localMetaPath.toFile())); fileList.forEach(entry -> result.add(entry.toString())); return result; }
ArrayList<Persona> personas; JSONParser jParser; JSONObject json; try { personas = new ArrayList<Persona>(); jParser = new JSONParser(); json = jParser.getJSONFromUrl(url); // rest of the code } catch(Exception e){}
public JSONParser jsonParser = new JSONParser(); try { // Building Parameters ( you can pass as many parameters as you want) List<NameValuePair> params = new ArrayList<NameValuePair>(); params.add(new BasicNameValuePair("name", name)); params.add(new BasicNameValuePair("age", 25)); // Getting JSON Object JSONObject json = jsonParser.makeHttpRequest(YOUR_URL, "POST", params); } catch (JSONException e) { e.printStackTrace(); }
private void setExtraEnvParams(String extraEnvParams) { try { if (null != extraEnvParams && extraEnvParams.length() > 0) { JSONParser parser = new JSONParser(); Object obj = parser.parse(extraEnvParams); JSONObject jsonObj = (JSONObject) obj; if (jsonObj.size() > 0) { for (Iterator iterator = jsonObj.keySet().iterator(); iterator.hasNext(); ) { String key = (String) iterator.next(); String val = (String) jsonObj.get(key); if (StringUtils.isNotBlank(key) && StringUtils.isNotBlank(val)) { System.setProperty(key.trim(), val.trim()); } } } } } catch (Exception e) { System.out.println( "Failed to parse extra env params: " + extraEnvParams + ". However, ignoring the exception."); e.printStackTrace(); } } }
JSONParser jsonParser = new JSONParser(); JSONObject payload = jsonParser.getJSONFromUrl( "http://yourdomain.com/path/to/your/api", null); System.out.println(payload.get("content");
JSONParser jParser = new JSONParser(); JSONObject json = jParser.getJSONFromUrl(URL); JSonArray deals = json.getJSONArray("user"); while(count < deals.length()) { JSONObject c = deals.getJSONObject(count); String offer = c.getString("discription"); String title = c.getString("title"); count++; }
String url = "your url"; JSONParser jsonParser = new JSONParser(); JSONObject object = jsonParser.getJSONFromUrl(url); String content=object.getString("json key");
//Write your own implementation of json parser JSONParser jParser = new JSONParser(); JSONArray prod_cat = new JSONArray(); JSONArray products = new JSONArray(); JSONObject json = jParser.getJSONFromUrl("your source"); prod_cat = json.getJSONArray("prodCat_list"); for (int i = 0; i < prod_cat.length(); i++) { JSONObject object = prod_cat.getJSONObject(i); products = object.getJSONArray("products"); }
JSONParser jParser=new JSONParser(); JSONArray json=jParser.getJSONFromUrl(yourUrl); try { for(int i=0;i<json.length();i++) { JSONObject c=json.getJSONObject(i);// Used JSON Object from Android places[i]=c.getInt("id"); } } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); }
public static void remove(String dflowname) throws IOException, ParseException { String jsonResponse = ""; URL url = new URL(deleteuri); HttpURLConnection connection = null; connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("POST"); // We have to override the post method so we can send data connection.setRequestProperty("X-HTTP-Method-Override", "DELETE"); connection.setDoOutput(true); // Send request OutputStreamWriter wr = new OutputStreamWriter( connection.getOutputStream()); wr.write(dflowname); wr.flush(); // Get Response BufferedReader rd = new BufferedReader(new InputStreamReader(connection.getInputStream())); String line; while ((line = rd.readLine()) != null) { jsonResponse = jsonResponse.concat(line); } wr.close(); rd.close(); JSONParser parser = new JSONParser(); JSONObject obj = (JSONObject) parser.parse(jsonResponse); System.out.println(obj.get("status").toString()); }
ArrayList<ACL> newDefault = new ArrayList<>(); try { JSONArray acls = (JSONArray) ((JSONObject) new JSONParser().parse(jsonAcl)).get("acls"); for (Iterator it = acls.iterator(); it.hasNext();) { JSONObject acl = (JSONObject) it.next();
@Override protected List<JSONObject> doInBackground(List<String>... urls) { List<JSONObject> jsonList = new ArrayList<JSONObject>(); JSONParser json_parse = new JSONParser(); for (int i = 0; i < urls[0].size(); i ++) { jsonList.add(json_parse.getJSONFromUrl(urls[0].get(i))); Log.d(TAG, "added " + i); } Log.d(TAG, "returning jsonList"); return jsonList; }
String url="place your url here"; JSONParser jparser= new JSONParser(); params = new ArrayList<NameValuePair>(); params.add(new BasicNameValuePair("tag", "getcategory")); params.add(new BasicNameValuePair("username", username.getText().toString())); params.add(new BasicNameValuePair("password", password.getText().toString())); JSONObject jobj= jparser.makeHttpRequest(url, "POST", params);
final JSONParser jParser = new JSONParser(); final JSONObject jObject = jParser.getJSONFromUrl(url); Iterator<?> keys = jObject.keys(); while(keys.hasNext()){ final String key = (String)keys.next(); final Object obj = jObject.get(key); if(obj instanceof JSONObject){ final String rate = jObject.getString(key); System.out.println(key + " => " + rate); list.add(rate); } }
JSONParser jParser = new JSONParser(); JSONObject json = jParser.getJSONFromUrl(url); JSONArray jArrayVersion = json.getJSONArray("result"); for (int j = 0; j < jArrayVersion.length(); j++) { JSONObject items = jArrayVersion.getJSONObject(j); String namesv = items.getString("name"); String message = items.getString("message"); }