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)); }
reset(in); LinkedList statusStack = new LinkedList(); LinkedList valueStack = new LinkedList(); nextToken(); switch(status){ case S_INIT: status=S_IN_OBJECT; statusStack.addFirst(new Integer(status)); valueStack.addFirst(createObjectContainer(containerFactory)); break; case Yytoken.TYPE_LEFT_SQUARE: status=S_IN_ARRAY; statusStack.addFirst(new Integer(status)); valueStack.addFirst(createArrayContainer(containerFactory)); break; default: return valueStack.removeFirst(); else throw new ParseException(getPosition(), ParseException.ERROR_UNEXPECTED_TOKEN, token); statusStack.removeFirst(); valueStack.removeFirst(); status=peekStatus(statusStack); Map parent=(Map)valueStack.getFirst(); parent.put(key,token.value);
JSONParser jParser = new JSONParser(); String json = jParser.getJSONFromUrl(url);
JSONParser parser = new JSONParser(); JSONObject json = (JSONObject) parser.parse(stringToParse);
super.onPreExecute(); pDialog = new ProgressDialog(getActivity()); pDialog.setMessage("Getting Data ..."); pDialog.setIndeterminate(false); pDialog.setCancelable(true); pDialog.show(); JSONParser jParser = new JSONParser(); JSONObject json = jParser.getJSONFromUrl(getItemsUrl); return json; for (int i = 0; i < titleArr.length(); i++) { final JSONObject titleObj = titleArr.getJSONObject(i); String title = titleObj.getString("title"); String description = titleObj.getString("description"); String imgUrl = titleObj.getString("img"); String date = titleObj.getString("date"); e.printStackTrace();
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 main(String[] args) throws IOException, JSONException, ParseException { try { JSONParser parser = new JSONParser(); Object obj = parser.parse(new FileReader("/home/Desktop/temp.json")); JSONObject objJsonObject = new JSONObject(obj.toString()); System.out.println(objJsonObject); JSONArray Liste = objJsonObject.getJSONArray("ListeCar"); String listeCar = Liste.getJSONObject(0).getString("id"); for (int i = 0; i < Liste.length(); i++) { String id = Liste.getJSONObject(i).getString("id"); System.out.println(id); String size = Liste.getJSONObject(i).getString("size"); System.out.println(size); String Orientation = Liste.getJSONObject(i).getString("Orientation"); System.out.println(Orientation); String Position = Liste.getJSONObject(i).getJSONObject("Position").toString(); System.out.println(Position); } } catch (JSONException e) { e.printStackTrace(); } }
private ProgressDialog pDialog; JSONParser jParser = new JSONParser(); protected void onPreExecute() { super.onPreExecute(); pDialog = new ProgressDialog(EventDetails.this); pDialog.setMessage("Just a moment..."); pDialog.setIndeterminate(false); pDialog.setCancelable(true); pDialog.show(); JSONObject json = jParser.makeHttpRequest(url_event_details, "GET", params); success = json.getInt(CONNECTION_STATUS); if (success == 1) { JSONArray eventsObj = json.getJSONArray(TABLE_EVENT); JSONObject details = eventsObj.getJSONObject(0); name = details.getString(COL_NAME); desc = details.getString(COL_DESC); date = details.getString(COL_DATE); e.printStackTrace();
JSONParser jsonParser = new JSONParser(); JSONArray history = null; pDialog = new ProgressDialog(Singlehistory.this); pDialog.setMessage("Loading patient information ..."); pDialog.setIndeterminate(false); pDialog.setCancelable(false); pDialog.show(); String json = jsonParser.getJSONFromURL(SINGLE_HISTORY, "GET", params); JSONObject jObj = new JSONObject(json); if(jObj != null){ history = jObj.getJSONArray(TAG_POST); if(history != null){ for(int i=0; i<history.length(); i++){ JSONObject c = history.getJSONObject(i); date = c.getString(TAG_DATE); diagnosis = c.getString(TAG_DIAGNOSIS); medication = c.getString(TAG_MEDICATION); e.printStackTrace();
JSONParser jParser = new JSONParser(); JSONObject json = jParser.getJSONFromUrl(url); try { result = json.getString("internalName"); data=json.getString("dataVersion"); ect.. } catch (JSONException e) { e.printStackTrace(); }
FileReader reader = new FileReader(filePath); JSONParser jsonParser = new JSONParser(); JSONObject jsonObject = (JSONObject) jsonParser.parse(reader); JSONObject jsonObject1 = (JSONObject) jsonObject.get("products"); JSONObject jsonObject2 = (JSONObject)jsonObject1.get("productsApp15"); String firstName = (String) jsonObject2.get("code").toString(); System.out.println("The first name is: " + firstName); jsonObject2.remove("code"); jsonObject2.put("code", "try"); JSONObject jsonObject3 = (JSONObject)jsonObject1.get("productsApp15"); String firstName2 = (String) jsonObject2.get("code").toString(); System.out.println("The first name is: " + firstName2);
private ProgressDialog Dialog = new ProgressDialog(ABC.this); Dialog.setMessage("Loading....."); Dialog.show(); JSONParser parser = new JSONParser(); JSONObject jsonObject = new JSONObject(); JSONArray aJson = jsonObject.getJSONFromUrl(url); contacts = aJson.getJSONObject(TAG_CATEGORY); String id = c.getString(CATEGORY_COLUMN_ID); String title = c.getString(CATEGORY_COLUMN_TITLE); String content = c.getString(CATEGORY_COLUMN_CONTENT); e.printStackTrace();
if (statsFile.exists()) { try { JSONParser parser = new JSONParser(); JSONObject json = (JSONObject) parser.parse(new FileReader(statsFile)); for (Object obj : json.entrySet()) { Map.Entry<String, Object> entry = (Map.Entry<String, Object>) obj; Long longValue = null; } else if (entry.getValue() instanceof JSONObject) { JSONObject object = (JSONObject) entry.getValue(); if (object.containsKey("value")) { // NON-NLS longValue = (Long) object.get("value"); // NON-NLS
@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; }
/** * Reloads from the file. */ public void load() { entries.clear(); if (file.exists()) { try (Reader reader = new FileReader(file)) { JSONArray jsonArray = (JSONArray) new JSONParser().parse(reader); for (Object object : jsonArray) { JSONObject jsonObj = (JSONObject) object; Map<String, String> map = new HashMap<>(jsonObj.size()); for (Object jsonEntry : jsonObj.entrySet()) { Entry<?, ?> entry = (Map.Entry<?, ?>) jsonEntry; map.put(entry.getKey().toString(), entry.getValue().toString()); } entries.add(readEntry(map)); } } catch (Exception ex) { GlowServer.logger.log(Level.SEVERE, "Error reading from: " + file, ex); } } else { //importLegacy(); save(); } }
TextView txtTitle; TextView txtDesc; JSONParser jParser = new JSONParser(); JSONArray articles = null; private ProgressDialog progressDialog = new ProgressDialog(SingleContactActivity.this); InputStream inputStream = null; String result = ""; progressDialog.setMessage("Downloading articles..."); progressDialog.show(); progressDialog.setOnCancelListener(new DialogInterface.OnCancelListener() { public void onCancel(DialogInterface arg0) { JSONObject json = jParser.makeHttpRequest(url_select, "GET", param); // Change "GET" to "POST" if you want the POST method articles = json.getJSONArray("article"); JSONObject jsonObj = articles.getJSONObject(0); title = jsonObj.getString("title"); description = jsonObj.getString("description"); Log.e("JSONException", e5.toString()); e5.printStackTrace();
protected void onPreExecute() { dialog = new ProgressDialog(GetData.this); dialog.setMessage("Searching Database"); dialog.show(); JSONParser jParser = new JSONParser(); JSON = jParser.getJSONFromUrl(url); if(json!=null && json.length()>0)// returning from doInBackground() if json is null return null; for (int i = 0; i < json.length(); i++) { JSONObject c = json.getJSONObject(i); String Listing_ID = c.getString(lblListing_ID); String Event_ID = c.getString(lblEvent_ID); String Venue_ID = c.getString(lblVenue_ID); String Start_Date = c.getString(lblStart_Date); String End_Date = c.getString(lblEnd_Date); e.printStackTrace(); if (dialog.isShowing()) { dialog.dismiss();
protected Set<String> getSchemaFields(String schema) throws FileNotFoundException, IOException, ParseException, URISyntaxException { Set<String> res = new HashSet<>(); JSONParser parser = new JSONParser(); JSONObject jsonObject = (JSONObject) parser.parse(new FileReader(this.getClass().getResource(schema).toURI().getPath())); JSONArray jsonArray = (JSONArray) jsonObject.get("fields"); jsonArray.iterator().forEachRemaining(o -> res.add(((JSONObject) o).get("name").toString())); return res; }
public class App { public static void main(final String[] args) throws FileNotFoundException, IOException, ParseException { final Object obj = new JSONParser().parse(new FileReader("D:/a.json")); final JSONObject jsonObject = (JSONObject) obj; final JSONObject user = (JSONObject) jsonObject.get("user"); final JSONArray list = (JSONArray) user.get("SomeList"); System.out.println(list); } }
... ... try { JSONParser jParser = new JSONParser(); JSONObject json = jParser.getJSONFromUrl(url+url_param); JSONArray result = json.getJSONArray("result"); if(result!=null) { for (int i = 0; i < result.length(); i++) { JSONObject c = (JSONObject) result.get(i); String id = "", pesan = "", nama_tipsntrick = "", kategori_tipsntrick = ""; if (c.has("id")) id = c.getString("id"); if (c.has("pesan")) pesan = c.getString("pesan"); if (c.has("nam")) nama_tipsntrick = c.getString("nama"); if (c.has("kategori")) kategori_tipsntrick = c.getString("kategori"); HashMap<String, String> map = new HashMap<String, String>(); map.put(in_id, id); map.put(in_pesan, pesan); map.put(in_nama, nama_tipsntrick); map.put(in_kategori, kategori_tipsntrick); resultList.add(map); } } Log.d("log", "bla:" + resultList); } catch (JSONException e) { e.printStackTrace(); }