List of usage examples for org.json JSONArray toString
public String toString()
From source file:de.kp.ames.web.function.domain.model.JsonAccessor.java
public void set(RegistryObjectImpl ro, Locale locale) throws JSONException, JAXRException { /*/*from w w w .java2s . co m*/ * Convert registry object */ super.set(ro, locale); /* * Convert accessor specific information */ ServiceImpl accessor = (ServiceImpl) ro; /* * Convert specifications */ JSONArray jArray = getSpecifications(accessor); put(JaxrConstants.RIM_SPEC, jArray.toString()); /* * Convert icon */ put(JaxrConstants.RIM_ICON, IconConstants.SERVICE); }
From source file:com.rs.TCOfflineStatementCollection.java
/** * Returns a JSON formatted string of the collection's contents * @return json string of all statements in collection *///from w w w .java 2s. c om String JSONString() { JSONArray array = new JSONArray(); for (int i = 0; i < _statementArray.size(); i++) { Statement st = _statementArray.get(i); try { array.put(i, st.toJSON()); } catch (Exception e) { return ""; } } String returnString = array.toString(); returnString = returnString.replace("\\", ""); return returnString; }
From source file:edu.cens.loci.classes.LociVisit.java
public String getRecognitionResults() { JSONArray jArr = new JSONArray(); for (RecognitionResult result : this.recognitions) { try {//from ww w . j a va2 s . co m jArr.put(result.toJsonObject()); } catch (JSONException e) { MyLog.e(LociConfig.D.JSON, TAG, "getRecognitionResults() : Json error."); e.printStackTrace(); } } return jArr.toString(); }
From source file:com.aware.utils.WebserviceHelper.java
@Override protected void onHandleIntent(Intent intent) { WEBSERVER = Aware.getSetting(getApplicationContext(), Aware_Preferences.WEBSERVICE_SERVER); DEVICE_ID = Aware.getSetting(getApplicationContext(), Aware_Preferences.DEVICE_ID); DEBUG = Aware.getSetting(getApplicationContext(), Aware_Preferences.DEBUG_FLAG).equals("true"); DATABASE_TABLE = intent.getStringExtra(EXTRA_TABLE); TABLES_FIELDS = intent.getStringExtra(EXTRA_FIELDS); CONTENT_URI = Uri.parse(intent.getStringExtra(EXTRA_CONTENT_URI)); //Fixed: not using webservices if (WEBSERVER.length() == 0) return;/*from w w w . j a v a 2 s . c o m*/ if (intent.getAction().equals(ACTION_AWARE_WEBSERVICE_SYNC_TABLE)) { //Check if we should do this only over Wi-Fi boolean wifi_only = Aware.getSetting(getApplicationContext(), Aware_Preferences.WEBSERVICE_WIFI_ONLY) .equals("true"); if (wifi_only) { ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo active_network = cm.getActiveNetworkInfo(); if (active_network != null && active_network.getType() != ConnectivityManager.TYPE_WIFI) { if (DEBUG) { Log.i("AWARE", "User not connected to Wi-Fi, skipping data sync."); } return; } } //Check first if we have database table remotely, otherwise create it! ArrayList<NameValuePair> fields = new ArrayList<NameValuePair>(); fields.add(new BasicNameValuePair(Aware_Preferences.DEVICE_ID, DEVICE_ID)); fields.add(new BasicNameValuePair(EXTRA_FIELDS, TABLES_FIELDS)); //Create table if doesn't exist on the remote webservice server HttpResponse response = new Https(getApplicationContext()) .dataPOST(WEBSERVER + "/" + DATABASE_TABLE + "/create_table", fields); if (response != null && response.getStatusLine().getStatusCode() == 200) { if (DEBUG) { HttpResponse copy = response; try { if (DEBUG) Log.d(Aware.TAG, EntityUtils.toString(copy.getEntity())); } catch (ParseException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } String[] columnsStr = new String[] {}; Cursor columnsDB = getContentResolver().query(CONTENT_URI, null, null, null, null); if (columnsDB != null && columnsDB.moveToFirst()) { columnsStr = columnsDB.getColumnNames(); if (DEBUG) Log.d(Aware.TAG, "Total records on " + DATABASE_TABLE + ": " + columnsDB.getCount()); } if (columnsDB != null && !columnsDB.isClosed()) columnsDB.close(); try { ArrayList<NameValuePair> request = new ArrayList<NameValuePair>(); request.add(new BasicNameValuePair(Aware_Preferences.DEVICE_ID, DEVICE_ID)); //check the latest entry in remote database HttpResponse latest = new Https(getApplicationContext()) .dataPOST(WEBSERVER + "/" + DATABASE_TABLE + "/latest", request); if (latest == null) return; String data = "[]"; try { data = EntityUtils.toString(latest.getEntity()); } catch (IllegalStateException e) { Log.d(Aware.TAG, "Unable to connect to webservices..."); } if (DEBUG) { Log.d(Aware.TAG, "Webservice response: " + data); } //If in a study, get from joined date onwards String study_condition = ""; if (Aware.getSetting(getApplicationContext(), "study_id").length() > 0 && Aware.getSetting(getApplicationContext(), "study_start").length() > 0) { String study_start = Aware.getSetting(getApplicationContext(), "study_start"); study_condition = " AND timestamp > " + Long.parseLong(study_start); } if (DATABASE_TABLE.equalsIgnoreCase("aware_device")) study_condition = ""; JSONArray remoteData = new JSONArray(data); Cursor context_data; if (remoteData.length() == 0) { if (exists(columnsStr, "double_end_timestamp")) { context_data = getContentResolver().query(CONTENT_URI, null, "double_end_timestamp != 0" + study_condition, null, "timestamp ASC"); } else if (exists(columnsStr, "double_esm_user_answer_timestamp")) { context_data = getContentResolver().query(CONTENT_URI, null, "double_esm_user_answer_timestamp != 0" + study_condition, null, "timestamp ASC"); } else { context_data = getContentResolver().query(CONTENT_URI, null, "1" + study_condition, null, "timestamp ASC"); } } else { long last = 0; if (exists(columnsStr, "double_end_timestamp")) { last = remoteData.getJSONObject(0).getLong("double_end_timestamp"); context_data = getContentResolver().query(CONTENT_URI, null, "timestamp > " + last + " AND double_end_timestamp != 0" + study_condition, null, "timestamp ASC"); } else if (exists(columnsStr, "double_esm_user_answer_timestamp")) { last = remoteData.getJSONObject(0).getLong("double_esm_user_answer_timestamp"); context_data = getContentResolver().query( CONTENT_URI, null, "timestamp > " + last + " AND double_esm_user_answer_timestamp != 0" + study_condition, null, "timestamp ASC"); } else { last = remoteData.getJSONObject(0).getLong("timestamp"); context_data = getContentResolver().query(CONTENT_URI, null, "timestamp > " + last + study_condition, null, "timestamp ASC"); } } JSONArray context_data_entries = new JSONArray(); if (context_data != null && context_data.moveToFirst()) { if (DEBUG) Log.d(Aware.TAG, "Uploading " + context_data.getCount() + " from " + DATABASE_TABLE); do { JSONObject entry = new JSONObject(); String[] columns = context_data.getColumnNames(); for (String c_name : columns) { //Skip local database ID if (c_name.equals("_id")) continue; if (c_name.equals("timestamp") || c_name.contains("double")) { entry.put(c_name, context_data.getDouble(context_data.getColumnIndex(c_name))); } else if (c_name.contains("float")) { entry.put(c_name, context_data.getFloat(context_data.getColumnIndex(c_name))); } else if (c_name.contains("long")) { entry.put(c_name, context_data.getLong(context_data.getColumnIndex(c_name))); } else if (c_name.contains("blob")) { entry.put(c_name, context_data.getBlob(context_data.getColumnIndex(c_name))); } else if (c_name.contains("integer")) { entry.put(c_name, context_data.getInt(context_data.getColumnIndex(c_name))); } else { entry.put(c_name, context_data.getString(context_data.getColumnIndex(c_name))); } } context_data_entries.put(entry); if (context_data_entries.length() == 1000) { request = new ArrayList<NameValuePair>(); request.add(new BasicNameValuePair(Aware_Preferences.DEVICE_ID, DEVICE_ID)); request.add(new BasicNameValuePair("data", context_data_entries.toString())); new Https(getApplicationContext()) .dataPOST(WEBSERVER + "/" + DATABASE_TABLE + "/insert", request); context_data_entries = new JSONArray(); } } while (context_data.moveToNext()); if (context_data_entries.length() > 0) { request = new ArrayList<NameValuePair>(); request.add(new BasicNameValuePair(Aware_Preferences.DEVICE_ID, DEVICE_ID)); request.add(new BasicNameValuePair("data", context_data_entries.toString())); new Https(getApplicationContext()) .dataPOST(WEBSERVER + "/" + DATABASE_TABLE + "/insert", request); } } else { if (DEBUG) Log.d(Aware.TAG, "Nothing new in " + DATABASE_TABLE + "!" + " URI=" + CONTENT_URI.toString()); } if (context_data != null && !context_data.isClosed()) context_data.close(); } catch (ParseException e) { e.printStackTrace(); } catch (JSONException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } } //Clear database table remotely if (intent.getAction().equals(ACTION_AWARE_WEBSERVICE_CLEAR_TABLE)) { ArrayList<NameValuePair> request = new ArrayList<NameValuePair>(); request.add(new BasicNameValuePair(Aware_Preferences.DEVICE_ID, DEVICE_ID)); new Https(getApplicationContext()).dataPOST(WEBSERVER + "/" + DATABASE_TABLE + "/clear_table", request); } }
From source file:com.pdi.hybridge.HybridgeBroadcaster.java
public void initJs(WebView view, JSONArray actions, JSONArray events) { runJsInWebView(view,/* w w w.j ava2 s. co m*/ "window.HybridgeGlobal || setTimeout(function () {" + "window.HybridgeGlobal = {" + " isReady : true" + ", version : " + HybridgeConst.VERSION + ", versionMinor : " + HybridgeConst.VERSION_MINOR + ", actions : " + actions.toString() + ", events : " + events.toString() + "};" + "},0)"); mIsInitialized = true; }
From source file:com.google.android.libraries.cast.companionlibrary.utils.Utils.java
/** * Builds and returns a {@link Bundle} which contains a select subset of data in the * {@link MediaInfo}. Since {@link MediaInfo} is not {@link Parcelable}, one can use this * container bundle to pass around from one activity to another. * * @see <code>bundleToMediaInfo()</code> *///w ww . j ava 2s . c o m public static Bundle mediaInfoToBundle(MediaInfo info) { if (info == null) { return null; } MediaMetadata md = info.getMetadata(); Bundle wrapper = new Bundle(); wrapper.putString(MediaMetadata.KEY_TITLE, md.getString(MediaMetadata.KEY_TITLE)); wrapper.putString(MediaMetadata.KEY_SUBTITLE, md.getString(MediaMetadata.KEY_SUBTITLE)); wrapper.putString(KEY_URL, info.getContentId()); wrapper.putString(MediaMetadata.KEY_STUDIO, md.getString(MediaMetadata.KEY_STUDIO)); wrapper.putString(KEY_CONTENT_TYPE, info.getContentType()); wrapper.putInt(KEY_STREAM_TYPE, info.getStreamType()); wrapper.putLong(KEY_STREAM_DURATION, info.getStreamDuration()); if (!md.getImages().isEmpty()) { ArrayList<String> urls = new ArrayList<>(); for (WebImage img : md.getImages()) { urls.add(img.getUrl().toString()); } wrapper.putStringArrayList(KEY_IMAGES, urls); } JSONObject customData = info.getCustomData(); if (customData != null) { wrapper.putString(KEY_CUSTOM_DATA, customData.toString()); } if (info.getMediaTracks() != null && !info.getMediaTracks().isEmpty()) { try { JSONArray jsonArray = new JSONArray(); for (MediaTrack mt : info.getMediaTracks()) { JSONObject jsonObject = new JSONObject(); jsonObject.put(KEY_TRACK_NAME, mt.getName()); jsonObject.put(KEY_TRACK_CONTENT_ID, mt.getContentId()); jsonObject.put(KEY_TRACK_ID, mt.getId()); jsonObject.put(KEY_TRACK_LANGUAGE, mt.getLanguage()); jsonObject.put(KEY_TRACK_TYPE, mt.getType()); if (mt.getSubtype() != MediaTrack.SUBTYPE_UNKNOWN) { jsonObject.put(KEY_TRACK_SUBTYPE, mt.getSubtype()); } if (mt.getCustomData() != null) { jsonObject.put(KEY_TRACK_CUSTOM_DATA, mt.getCustomData().toString()); } jsonArray.put(jsonObject); } wrapper.putString(KEY_TRACKS_DATA, jsonArray.toString()); } catch (JSONException e) { LOGE(TAG, "mediaInfoToBundle(): Failed to convert Tracks data to json", e); } } return wrapper; }
From source file:org.uiautomation.ios.IOSCapabilities.java
public List<Device> getSupportedDevicesFromDeviceFamily() { JSONArray o = (JSONArray) asMap().get(DEVICE_FAMILLY); List<Device> devices = new ArrayList<Device>(); for (int i = 0; i < o.length(); i++) { try {/*www . j a v a 2 s .co m*/ devices.add(Device.getFromFamilyCode(o.getInt(i))); } catch (JSONException e) { throw new WebDriverException(o.toString() + " but should contain only 1 or 2."); } } return devices; }
From source file:org.apache.nutch.util.TestProcessUtil.java
public static void main(String[] args) throws Exception { int res = 0;//w ww . j a va 2 s . c om JSONArray data = new JSONArray(Arrays.asList(args)); System.out.println("It's crowdsourcing mode, forward the command to NutchServer..."); ProcessBuilder builder = new ProcessBuilder("curl", "-v", "-H", "'Content-Type: application/json'", "-X", "PUT", "--data", data.toString(), "http://127.0.0.1:8182/exec/fetch"); System.out.println("Execute command : " + StringUtils.join(builder.command(), " ")); builder.inheritIO(); Process process = builder.start(); res = process.waitFor(); System.exit(res); }
From source file:org.nuxeo.html.utils.operations.HTMLGetLinksOp.java
@OperationMethod public String run(Blob inBlob) throws IOException, JSONException { JSONArray array = new JSONArray(); if (inBlob != null) { HTMLParser hp = new HTMLParser(inBlob); ArrayList<LinkInfo> links = hp.getLinks(); array = buildJsonString(links);//from w ww. java2 s. com } return array.toString(); }
From source file:org.nuxeo.html.utils.operations.HTMLGetLinksOp.java
@OperationMethod public String run(DocumentModel inDoc) throws IOException, JSONException { JSONArray array = new JSONArray(); if (inDoc != null) { HTMLParser hp = new HTMLParser(inDoc, xpath); ArrayList<LinkInfo> links = hp.getLinks(); array = buildJsonString(links);//from w ww. java 2 s. c o m } return array.toString(); }