org.json.JSONException Java Examples

The following examples show how to use org.json.JSONException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WvWebView.java    From YCWebView with Apache License 2.0 7 votes vote down vote up
private JSONObject messageToJsonObject(WvMessage message) {
    JSONObject jo = new JSONObject();
    try {
        if (message.callbackId != null) {
            jo.put(CALLBACK_ID_STR, message.callbackId);
        }
        if (message.data != null) {
            jo.put(DATA_STR, message.data);
        }
        if (message.handlerName != null) {
            jo.put(HANDLER_NAME_STR, message.handlerName);
        }
        if (message.responseId != null) {
            jo.put(RESPONSE_ID_STR, message.responseId);
        }
        if (message.responseData != null) {
            jo.put(RESPONSE_DATA_STR, message.responseData);
        }
    } catch (JSONException e) {
        e.printStackTrace();
    }
    return jo;
}
 
Example #2
Source File: SelfDescribingJsonTest.java    From snowplow-android-tracker with Apache License 2.0 6 votes vote down vote up
public void testCreateWithSelfDescribingJsonWithMore() throws JSONException {
    testMap.put("a", "b");
    testMap.put("c", "d");
    SelfDescribingJson json = new SelfDescribingJson(testSchema, new SelfDescribingJson(testSchema, testMap));

    // {"schema":"org.test.scheme","data":{"schema":"org.test.scheme","data":{"a":"b","c":"d"}}}
    String s = json.toString();

    JSONObject map = new JSONObject(s);
    assertEquals(testSchema, map.getString("schema"));
    JSONObject innerMap = map.getJSONObject("data");
    assertEquals(testSchema, innerMap.getString("schema"));
    JSONObject innerData = innerMap.getJSONObject("data");
    assertEquals(2, innerData.length());
    assertEquals("b", innerData.getString("a"));
    assertEquals("d", innerData.getString("c"));
}
 
Example #3
Source File: MainActivity.java    From SocketIO_Chat_APP with MIT License 6 votes vote down vote up
public void sendMessage(View view){
    Log.i(TAG, "sendMessage: ");
    String message = textField.getText().toString().trim();
    if(TextUtils.isEmpty(message)){
        Log.i(TAG, "sendMessage:2 ");
        return;
    }
    textField.setText("");
    JSONObject jsonObject = new JSONObject();
    try {
        jsonObject.put("message", message);
        jsonObject.put("username", Username);
        jsonObject.put("uniqueId", uniqueId);
    } catch (JSONException e) {
        e.printStackTrace();
    }
    Log.i(TAG, "sendMessage: 1"+ mSocket.emit("chat message", jsonObject));
}
 
Example #4
Source File: WebTrace.java    From ArgusAPM with Apache License 2.0 6 votes vote down vote up
public static void dispatch(JSONObject jsonObject) {
    if (!Manager.getInstance().getTaskManager().taskIsCanWork(ApmTask.TASK_WEBVIEW)) {
        if (Env.DEBUG) {
            LogX.d(Env.TAG, SUB_TAG, "webview task is not work");
        }
        return;
    }
    ITask task = Manager.getInstance().getTaskManager().getTask(ApmTask.TASK_WEBVIEW);
    if (task != null && jsonObject != null) {
        try {
            WebInfo webInfo = new WebInfo();
            webInfo.url = jsonObject.getString(WebInfo.DBKey.KEY_URL);
            webInfo.isWifi = SystemUtils.isWifiConnected();
            webInfo.navigationStart = jsonObject.getLong(WebInfo.DBKey.KEY_NAVIGATION_START);
            webInfo.responseStart = jsonObject.getLong(WebInfo.DBKey.KEY_RESPONSE_START);
            webInfo.pageTime = jsonObject.getLong(WebInfo.DBKey.KEY_PAGE_TIME);
            task.save(webInfo);
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
}
 
Example #5
Source File: MediaSerializer.java    From KlyphMessenger with MIT License 6 votes vote down vote up
@Override
public JSONObject serializeObject(GraphObject object)
{
	JSONObject json = new JSONObject();
	serializePrimitives(object, json);
	
	Media media = (Media) object;

	PhotoSerializer ps = new PhotoSerializer();
	VideoSerializer vs = new VideoSerializer();
	SwfSerializer swfs = new SwfSerializer();
	
	try
	{
		json.put("photo", ps.serializeObject(media.getPhoto()));
		json.put("video", vs.serializeObject(media.getVideo()));
		json.put("swf", swfs.serializeObject(media.getSwf()));
	}
	catch (JSONException e)
	{
		Log.d("MediaSerializer", "JsonException " + e);
	}
	
	return json;
}
 
Example #6
Source File: NewActivity.java    From StreamHub-Android-SDK with MIT License 6 votes vote down vote up
@Override
public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONObject errorResponse) {
    super.onFailure(statusCode, headers, throwable, errorResponse);
    dismissProgressDialog();
    try {
        if (!errorResponse.isNull("msg")) {
            showAlert(errorResponse.getString("msg"), "TRY AGAIN", tryAgain);
        } else {
            showAlert("Something went wrong.", "TRY AGAIN", tryAgain);
        }
    } catch (JSONException e) {
        e.printStackTrace();
        showAlert("Something went wrong.", "TRY AGAIN", tryAgain);

    }
}
 
Example #7
Source File: OpenAPIParser.java    From DeviceConnect-Android with MIT License 6 votes vote down vote up
/**
 * 応答用定義の解析を行います.
 *
 * @param jsonObject 応答用定義が格納されたJSONオブジェクト
 * @return 応答用定義
 * @throws JSONException JSONの解析に失敗した場合に発生
 */
private static Response parseResponse(JSONObject jsonObject) throws JSONException {
    Response response = new Response();
    for (Iterator<String> it = jsonObject.keys(); it.hasNext();) {
        String key = it.next();
        Object object = jsonObject.get(key);
        if (object != null) {
            if ("description".equalsIgnoreCase(key)) {
                response.setDescription((String) object);
            } else if ("schema".equalsIgnoreCase(key)) {
                response.setSchema(parseSchema((JSONObject) object));
            } else if ("headers".equalsIgnoreCase(key)) {
                response.setHeaders(parseHeaders((JSONObject) object));
            } else if ("examples".equalsIgnoreCase(key)) {
                response.setExamples(parseExamples((JSONObject) object));
            } else if (key.startsWith("x-")) {
                response.addVendorExtension(key, parseVendorExtension(object));
            }
        }
    }
    return response;
}
 
Example #8
Source File: GiftBeanParser.java    From letv with Apache License 2.0 6 votes vote down vote up
public GiftBean parser(String jsonString) {
    LogInfo.log("GiftBeanParser", "GiftBeanParser + GiftBeanString =" + jsonString);
    GiftBean giftBean = new GiftBean();
    if (!TextUtils.isEmpty(jsonString)) {
        try {
            JSONObject json = new JSONObject(jsonString);
            giftBean.is_first = json.optBoolean("is_first", true);
            giftBean.big_type = json.optInt("big_type");
            giftBean.title = json.optString("title");
            giftBean.price_image = json.optString("price_image");
            giftBean.company_name = json.optString("company_name");
        } catch (JSONException e) {
            LogInfo.log("GiftBeanParser", "jsonString error");
            e.printStackTrace();
        }
    }
    LogInfo.log("GiftBeanParser", "parser + GiftBean =" + giftBean.toString());
    return giftBean;
}
 
Example #9
Source File: JsonUtil.java    From AppAuth-Android with Apache License 2.0 6 votes vote down vote up
public static <T> List<T> get(JSONObject json, ListField<T> field) {
    try {
        if (!json.has(field.key)) {
            return field.defaultValue;
        }
        Object value = json.get(field.key);
        if (!(value instanceof JSONArray)) {
            throw new IllegalStateException(field.key
                    + " does not contain the expected JSON array");
        }
        JSONArray arrayValue = (JSONArray) value;
        ArrayList<T> values = new ArrayList<>();
        for (int i = 0; i < arrayValue.length(); i++) {
            values.add(field.convert(arrayValue.getString(i)));
        }
        return values;
    } catch (JSONException e) {
        // all appropriate steps are taken above to avoid a JSONException. If it is still
        // thrown, indicating an implementation change, throw an excpetion
        throw new IllegalStateException("unexpected JSONException", e);
    }
}
 
Example #10
Source File: Tencent.java    From YiBo with Apache License 2.0 6 votes vote down vote up
@Override
public Status createFavorite(String statusId) throws LibException {
	if (StringUtil.isEmpty(statusId)) {
		throw new LibException(LibResultCode.E_PARAM_NULL);
	}

	try {
		HttpRequestWrapper httpRequestWrapper = new HttpRequestWrapper(HttpMethod.POST, conf.getCreateFavoriteUrl(), auth);
		httpRequestWrapper.addParameter("id", statusId);
		httpRequestWrapper.addParameter("format", RESPONSE_FORMAT);
		String response = HttpRequestHelper.execute(httpRequestWrapper, responseHandler);
		JSONObject json = new JSONObject(response);
		Status status = new Status();
		status.setStatusId(ParseUtil.getRawString("id", json));
		status.setServiceProvider(ServiceProvider.Tencent);
		return status;
	} catch (JSONException e) {
		throw new LibException(LibResultCode.JSON_PARSE_ERROR, e);
	}
}
 
Example #11
Source File: Directions.java    From MapNavigator with Apache License 2.0 6 votes vote down vote up
private void parseDirections(){
	try {
		JSONObject json = new JSONObject(directions);

		
		if(!json.isNull("routes")){
			JSONArray route = json.getJSONArray("routes");
			
			for(int k=0;k<route.length(); k++){
				
				JSONObject obj3 = route.getJSONObject(k);
				routes.add(new Route(obj3));
			}
		}
		
	} catch (JSONException e) {
		e.printStackTrace();
	}
}
 
Example #12
Source File: TestUtils.java    From ambry with Apache License 2.0 6 votes vote down vote up
protected JSONArray getDatacenters(boolean createNew) throws JSONException {
  List<String> names = new ArrayList<String>(datacenterCount);
  if (createNew) {
    datanodeJSONArrays = new ArrayList<JSONArray>(datacenterCount);
  }

  int curBasePort = basePort;
  int sslPort = curBasePort + 10000;
  int http2Port = sslPort + 10000;
  for (int i = 0; i < datacenterCount; i++) {
    names.add(i, "DC" + i);
    if (createNew) {
      datanodeJSONArrays.add(i, getDataNodes(curBasePort, sslPort, http2Port, getDisks()));
    } else {
      updateDataNodeJsonArray(datanodeJSONArrays.get(i), curBasePort, sslPort, http2Port, getDisks());
    }
    curBasePort += dataNodeCount;
  }

  basePort += dataNodeCount;
  return TestUtils.getJsonArrayDatacenters(names, datanodeJSONArrays);
}
 
Example #13
Source File: CPU.java    From drmips with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Parses and sets the identifiers of the registers.
 * @param cpu The CPU to set the registers informations.
 * @param regs JSONArray that contains the registers.
 * @throws JSONException If the JSON file is malformed.
 * @throws InvalidCPUException If not all registers are specified or a register is invalid.
 */
private static void parseJSONRegNames(CPU cpu, JSONArray regs) throws JSONException, InvalidCPUException {
	if(regs.length() != cpu.getRegBank().getNumberOfRegisters())
		throw new InvalidCPUException("Not all registers have been specified in the registers block!");
	cpu.registerNames = new ArrayList<>(cpu.getRegBank().getNumberOfRegisters());
	String id;

	for(int i = 0; i < regs.length(); i++) {
		id = regs.getString(i).trim().toLowerCase();

		if(id.isEmpty())
			throw new InvalidCPUException("Invalid name " + id + "!");
		if(!id.matches(REGNAME_REGEX)) // has only letters and digits and starts with a letter?
			throw new InvalidCPUException("Invalid name " + id + "!");
		if(cpu.hasRegister(REGISTER_PREFIX + id))
			throw new InvalidCPUException("Invalid name " + id + "!");

		cpu.registerNames.add(id);
	}
}
 
Example #14
Source File: ApiApp.java    From hellosign-java-sdk with MIT License 6 votes vote down vote up
/**
 * Constructor that instantiates an ApiApp object based on the JSON response from the HelloSign
 * API.
 *
 * @param json JSONObject
 * @throws HelloSignException thrown if there is a problem parsing the JSONObject
 */
public ApiApp(JSONObject json) throws HelloSignException {
    super(json, APIAPP_KEY);
    owner_account = new Account(dataObj, APIAPP_OWNER_ACCOUNT);
    if (dataObj.has(ApiAppOauth.APIAPP_OAUTH_KEY) && !dataObj
        .isNull(ApiAppOauth.APIAPP_OAUTH_KEY)) {
        oauth = new ApiAppOauth(dataObj);
    }
    if (dataObj.has(WhiteLabelingOptions.WHITE_LABELING_OPTIONS_KEY)
        && !dataObj.isNull(WhiteLabelingOptions.WHITE_LABELING_OPTIONS_KEY)) {
        white_labeling_options = new WhiteLabelingOptions(dataObj);
        try {
            // Re-save the JSON Object back to the parent object, since
            // we are currently returning this as a string
            dataObj.put(WhiteLabelingOptions.WHITE_LABELING_OPTIONS_KEY,
                white_labeling_options.dataObj);
        } catch (JSONException e) {
            throw new HelloSignException("Unable to process white labeling options");
        }
    }
}
 
Example #15
Source File: UmbelSearchConcept.java    From wandora with GNU General Public License v3.0 6 votes vote down vote up
private ArrayList<String> getAsStringArray(Object o) throws JSONException {
    ArrayList<String> array = new ArrayList();
    if(o != null) {
        if(o instanceof String) {
            array.add(o.toString());
        }
        else if(o instanceof JSONArray) {
            JSONArray a = (JSONArray) o;
            for(int i=0; i<a.length(); i++) {
                String typeUri = a.getString(i);
                array.add(typeUri);
            }
        }
    }
    return array;
}
 
Example #16
Source File: YahooStockQuoteRepository.java    From ministocks with MIT License 6 votes vote down vote up
JSONArray retrieveQuotesAsJson(Cache cache, List<String> symbols) throws JSONException {
    String csvText = getQuotesCsv(cache, symbols);
    if (isDataInvalid(csvText)) {
        return null;
    }

    JSONArray quotes = new JSONArray();
    for (String line : csvText.split("\n")) {
        String[] values = parseCsvLine(line);
        if (isCsvLineInvalid(values, symbols)) {
            continue;
        }

        JSONObject data = new JSONObject();
        data.put("symbol", values[0]);
        data.put("price", values[3]);
        data.put("change", values[4]);
        data.put("percent", values[5]);
        data.put("exchange", values[6]);
        data.put("volume", values[7]);
        data.put("name", values[8]);
        quotes.put(data);
    }

    return quotes;
}
 
Example #17
Source File: GitCloneHandlerV1.java    From orion.server with Eclipse Public License 1.0 6 votes vote down vote up
public static void doConfigureClone(Git git, String user, String gitUserName, String gitUserMail) throws IOException, CoreException, JSONException {
	StoredConfig config = git.getRepository().getConfig();
	if (gitUserName == null && gitUserMail == null) {
		JSONObject gitUserConfig = getUserGitConfig(user);
		if (gitUserConfig != null) {
			gitUserName = gitUserConfig.getString("GitName"); //$NON-NLS-1$
			gitUserMail = gitUserConfig.getString("GitMail"); //$NON-NLS-1$
		}
	}
	if (gitUserName != null)
		config.setString(ConfigConstants.CONFIG_USER_SECTION, null, ConfigConstants.CONFIG_KEY_NAME, gitUserName);
	if (gitUserMail != null)
		config.setString(ConfigConstants.CONFIG_USER_SECTION, null, ConfigConstants.CONFIG_KEY_EMAIL, gitUserMail);

	config.setBoolean(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_FILEMODE, false);
	config.save();
}
 
Example #18
Source File: VectorLayer.java    From android_maplib with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void fillFromGeoJson(
        Uri uri,
        int srs,
        IProgressor progressor)
        throws IOException, JSONException, NGException, SQLiteException
{
    InputStream inputStream = mContext.getContentResolver().openInputStream(uri);
    if (inputStream == null) {
        throw new NGException(mContext.getString(R.string.error_download_data));
    }

    if (null != progressor) {
        progressor.setMessage(mContext.getString(R.string.create_features));
    }
    GeoJSONUtil.fillLayerFromGeoJSONStream(this, inputStream, srs, progressor);
}
 
Example #19
Source File: RouterServiceValidator.java    From sdl_java_suite with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
protected boolean verifyVersion(int version, JSONArray versions){
	if(version<0){
		return false;
	}
	if(versions == null || versions.length()==0){
		return true;
	}
	for(int i=0;i<versions.length();i++){
		try {
			if(version == versions.getInt(i)){
				return false;
			}
		} catch (JSONException e) {
			continue;
		}
	}//We didn't find our version in the black list.
	return true;
}
 
Example #20
Source File: KpiResource.java    From Knowage-Server with GNU Affero General Public License v3.0 6 votes vote down vote up
@POST
@Path("/getKpiTemplate")
public String loadTemplate(@Context HttpServletRequest req)
		throws EMFUserError, EMFInternalError, JSONException, TransformerFactoryConfigurationError, TransformerException {
	ObjTemplate template;
	try {
		JSONObject request = RestUtilities.readBodyAsJSONObject(req);

		template = DAOFactory.getObjTemplateDAO().getBIObjectActiveTemplate(request.getInt("id"));
		if (template == null) {
			return new JSONObject().toString();
		}

	} catch (Exception e) {
		logger.error("Error converting JSON Template to XML...", e);
		throw new SpagoBIServiceException(this.request.getPathInfo(), "An unexpected error occured while executing service", e);

	}
	return new JSONObject(Xml.xml2json(new String(template.getContent()))).toString();

}
 
Example #21
Source File: VideoStream.java    From cordova-rtmp-rtsp-stream with Apache License 2.0 6 votes vote down vote up
@Override
public void onRequestPermissionResult(int requestCode, String[] permissions, int[] grantResults) throws JSONException {
    int i = 0;
    for (int r : grantResults) {
        if (r == PackageManager.PERMISSION_DENIED) {
            this.callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, PERMISSION_DENIED_ERROR +
                    " Request Code: " + REQ_CODE + ", Actions: " + _action + ", Permission: " + permissions[i]));
            return;
        }
        i++;
    }

    if (requestCode == REQ_CODE) {
        this._methods(_action, _args);
    }
}
 
Example #22
Source File: InstanceRegisteredEventMixinTest.java    From spring-boot-admin with Apache License 2.0 6 votes vote down vote up
@Test
public void verifyDeserializeWithOnlyRequiredProperties() throws JSONException, JsonProcessingException {
	String json = new JSONObject().put("instance", "test123").put("timestamp", 1587751031.000000000)
			.put("type", "REGISTERED")
			.put("registration",
					new JSONObject().put("name", "test").put("healthUrl", "http://localhost:9080/heath"))
			.toString();

	InstanceRegisteredEvent event = objectMapper.readValue(json, InstanceRegisteredEvent.class);
	assertThat(event).isNotNull();
	assertThat(event.getInstance()).isEqualTo(InstanceId.of("test123"));
	assertThat(event.getVersion()).isEqualTo(0L);
	assertThat(event.getTimestamp()).isEqualTo(Instant.ofEpochSecond(1587751031).truncatedTo(ChronoUnit.SECONDS));

	Registration registration = event.getRegistration();
	assertThat(registration).isNotNull();
	assertThat(registration.getName()).isEqualTo("test");
	assertThat(registration.getManagementUrl()).isNull();
	assertThat(registration.getHealthUrl()).isEqualTo("http://localhost:9080/heath");
	assertThat(registration.getServiceUrl()).isNull();
	assertThat(registration.getSource()).isNull();
	assertThat(registration.getMetadata()).isEmpty();
}
 
Example #23
Source File: ModalPresenterTest.java    From react-native-navigation with MIT License 5 votes vote down vote up
@Test
public void showModal_resolvesDefaultOptions() throws JSONException {
    Options defaultOptions = new Options();
    JSONObject disabledShowModalAnimation = new JSONObject().put("enabled", false);
    defaultOptions.animations.showModal = new AnimationOptions(disabledShowModalAnimation);

    uut.setDefaultOptions(defaultOptions);
    uut.showModal(modal1, root, new CommandListenerAdapter());
    verifyZeroInteractions(animator);
}
 
Example #24
Source File: JsonAsyncHttpResponse.java    From AsyncOkHttpClient with Apache License 2.0 5 votes vote down vote up
@Override
protected void sendFailMessage(Throwable error, String responseBody) {
	try {
		Object jsonResponse = parseResponse(responseBody);
		if(jsonResponse == null) {
			sendMessage(obtainMessage(FAIL_JSON, new Object[] {error, responseBody}));
		} else {
			sendMessage(obtainMessage(FAIL_JSON, new Object[] {error, jsonResponse}));
		}
	} catch(JSONException e) {
		sendMessage(obtainMessage(FAIL_JSON, new Object[] {e, responseBody}));
	}
}
 
Example #25
Source File: JSONObjectResult.java    From codewind-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected boolean getBoolean(String key) {
	boolean value = false;
	if (result.has(key)) {
		try {
			value = result.getBoolean(key);
		} catch (JSONException e) {
			Logger.logError("An error occurred retrieving the value from the " + type + " object for key: " + key, e);
		}
	} else {
		Logger.logError("The " + type + " object did not have the expected key: " + key);
	}
	return value;
}
 
Example #26
Source File: ANVideoPlayerSettingsTest.java    From mobile-sdk-android with Apache License 2.0 5 votes vote down vote up
@Test
public void testInstreamSkipSettingsFalse() {
    ANVideoPlayerSettings.getVideoPlayerSettings().shouldShowSkip(false);
    String json = ANVideoPlayerSettings.getVideoPlayerSettings().fetchInStreamVideoSettings();
    try{
        JSONObject jsonObject = new JSONObject(json);
        JSONObject videoOptions = JsonUtil.getJSONObject(jsonObject,ANVideoPlayerSettings.AN_VIDEO_OPTIONS);
        JSONObject skippableOptions = JsonUtil.getJSONObject(videoOptions,ANVideoPlayerSettings.AN_SKIP);
        assertFalse(JsonUtil.getJSONBoolean(skippableOptions,ANVideoPlayerSettings.AN_ENABLED));
    }catch (JSONException e){
        e.printStackTrace();
    }
}
 
Example #27
Source File: Trigger.java    From AndroidAPS with GNU Affero General Public License v3.0 5 votes vote down vote up
@Nullable
public static Trigger instantiate(JSONObject object) {
    try {
        String type = object.getString("type");
        JSONObject data = object.getJSONObject("data");
        Class clazz = Class.forName(type);
        return ((Trigger) clazz.newInstance()).fromJSON(data.toString());
    } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | JSONException e) {
        log.error("Unhandled exception", e);
    }
    return null;
}
 
Example #28
Source File: WhoisResult.java    From PretendYoureXyzzyAndroid with GNU General Public License v3.0 5 votes vote down vote up
public WhoisResult(JSONObject obj) throws JSONException {
    super(obj);

    connectedAt = obj.getLong("ca");
    idle = obj.getLong("idl");

    if (CommonUtils.isStupidNull(obj, "gi")) game = null;
    else game = new Game(obj.getJSONObject("gi"));

    ipAddr = optString(obj, "IP");
    client = optString(obj, "cn");
}
 
Example #29
Source File: JsonConvert.java    From react-native-cordova with MIT License 5 votes vote down vote up
public static JSONArray reactToJSON(ReadableArray readableArray) throws JSONException {
    JSONArray jsonArray = new JSONArray();
    for(int i=0; i < readableArray.size(); i++) {
        ReadableType valueType = readableArray.getType(i);
        switch (valueType){
            case Null:
                jsonArray.put(JSONObject.NULL);
                break;
            case Boolean:
                jsonArray.put(readableArray.getBoolean(i));
                break;
            case Number:
                try {
                    jsonArray.put(readableArray.getInt(i));
                } catch(Exception e) {
                    jsonArray.put(readableArray.getDouble(i));
                }
                break;
            case String:
                jsonArray.put(readableArray.getString(i));
                break;
            case Map:
                jsonArray.put(reactToJSON(readableArray.getMap(i)));
                break;
            case Array:
                jsonArray.put(reactToJSON(readableArray.getArray(i)));
                break;
        }
    }
    return jsonArray;
}
 
Example #30
Source File: WebOSTVServiceConfig.java    From Connect-SDK-Android-Core with Apache License 2.0 5 votes vote down vote up
@Override
public JSONObject toJSONObject() {
    JSONObject jsonObj = super.toJSONObject();

    try {
        jsonObj.put(KEY_CLIENT_KEY, clientKey);
        jsonObj.put(KEY_CERT, exportCertificateToPEM(cert));
    } catch (JSONException e) {
        e.printStackTrace();
    }

    return jsonObj;
}