当前位置: 首页>>代码示例>>Java>>正文


Java JSONArray.toString方法代码示例

本文整理汇总了Java中org.json.JSONArray.toString方法的典型用法代码示例。如果您正苦于以下问题:Java JSONArray.toString方法的具体用法?Java JSONArray.toString怎么用?Java JSONArray.toString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.json.JSONArray的用法示例。


在下文中一共展示了JSONArray.toString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: postDecodeTracks

import org.json.JSONArray; //导入方法依赖的package包/类
@PostMapping(value = "/decodetracks", consumes = "application/json", produces = "application/json")
@ResponseBody
public String postDecodeTracks(HttpServletRequest request, HttpServletResponse response, @RequestBody String body) throws IOException {
    log(request);

    if (!isAuthorized(request, response))
        return "";

    JSONArray requestJSON = new JSONArray(body);
    JSONArray responseJSON = new JSONArray();

    for (int i = 0; i < requestJSON.length(); i++) {
        String track = requestJSON.getString(i);
        AudioTrack audioTrack = Util.toAudioTrack(track);

        JSONObject infoJSON = trackToJSON(audioTrack);
        JSONObject trackJSON = new JSONObject()
                .put("track", track)
                .put("info", infoJSON);

        responseJSON.put(trackJSON);
    }

    return responseJSON.toString();
}
 
开发者ID:Frederikam,项目名称:Lavalink,代码行数:26,代码来源:AudioLoaderRestHandler.java

示例2: serialize

import org.json.JSONArray; //导入方法依赖的package包/类
private static String serialize(List<GenericAppConfig> configs) throws JSONException {
	JSONArray list = new JSONArray();
	for (GenericAppConfig config : configs) {
		JSONObject object = new JSONObject();
		object.put(FIELD_ALERT_TYPE, config.getAlertType().getAlertId());
		object.put(FIELD_APP_DISPLAY_NAME, config.getAppDisplayName());
		object.put(FIELD_PACKAGE, config.getAppPackage());
		List<String> filters = config.getMessageFilters();
		JSONArray filtersArray = new JSONArray();
		for( String filter : filters ) {
			filtersArray.put(filter);
		}
		object.put(FIELD_MESSAGE_FILTERS, filtersArray);
		object.put(FIELD_PREFIX, config.getPrefix());
		object.put(FIELD_LABEL, config.getLabel());
		list.put(object);
	}
	return list.toString(1);
}
 
开发者ID:masterjc,项目名称:bluewatcher,代码行数:20,代码来源:GenericAppConfigManager.java

示例3: formatJson

import org.json.JSONArray; //导入方法依赖的package包/类
/**
 * json 格式化输出
 *
 * @param json json字符串
 * @return 用四个空格缩进后的json字符串结果
 */
public static String formatJson(String json) {
    String formatted = "";
    if (json == null || json.length() == 0) {
        return formatted;
    }
    try {
        if (json.startsWith("{")) {
            JSONObject jo = new JSONObject(json);
            formatted = jo.toString(JSON_INDENT);
        } else if (json.startsWith("[")) {
            JSONArray ja = new JSONArray(json);
            formatted = ja.toString(JSON_INDENT);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return formatted;
}
 
开发者ID:dueros,项目名称:dcs-sdk-java,代码行数:25,代码来源:CommonUtil.java

示例4: format

import org.json.JSONArray; //导入方法依赖的package包/类
@Override
public String format(String json) {
  String formattedString = null;
  if (json == null || json.trim().length() == 0) {
    throw new FormatException("JSON empty.");
  }
  try {
    if (json.startsWith("{")) {
      JSONObject jsonObject = new JSONObject(json);
      formattedString = jsonObject.toString(JSON_INDENT);
    } else if (json.startsWith("[")) {
      JSONArray jsonArray = new JSONArray(json);
      formattedString = jsonArray.toString(JSON_INDENT);
    } else {
      throw new FormatException("JSON should start with { or [, but found " + json);
    }
  } catch (Exception e) {
    throw new FormatException("Parse JSON error. JSON string:" + json, e);
  }
  return formattedString;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:22,代码来源:DefaultJsonFormatter.java

示例5: jsonFormat

import org.json.JSONArray; //导入方法依赖的package包/类
/**
 * json 格式化
 * @param bodyString
 * @return
 */
public static String jsonFormat(String bodyString) {
    String message;
    try {
        if (bodyString.startsWith("{")) {
            JSONObject jsonObject = new JSONObject(bodyString);
            message = jsonObject.toString(4);
        } else if (bodyString.startsWith("[")) {
            JSONArray jsonArray = new JSONArray(bodyString);
            message = jsonArray.toString(4);
        } else {
            message = bodyString;
        }
    } catch (JSONException e) {
        message = bodyString;
    }
    return message;
}
 
开发者ID:hshare,项目名称:MVPArmsTest1,代码行数:23,代码来源:CharactorHandler.java

示例6: printJson

import org.json.JSONArray; //导入方法依赖的package包/类
public static void printJson(String tag, String msg, String headString) {

        String message;

        try {
            if (msg.startsWith("{")) {
                JSONObject jsonObject = new JSONObject(msg);
                message = jsonObject.toString(KLog.JSON_INDENT);
            } else if (msg.startsWith("[")) {
                JSONArray jsonArray = new JSONArray(msg);
                message = jsonArray.toString(KLog.JSON_INDENT);
            } else {
                message = msg;
            }
        } catch (JSONException e) {
            message = msg;
        }

        KLogUtil.printLine(tag, true);
        message = headString + KLog.LINE_SEPARATOR + message;
        String[] lines = message.split(KLog.LINE_SEPARATOR);
        for (String line : lines) {
            Log.d(tag, "║ " + line);
        }
        KLogUtil.printLine(tag, false);
    }
 
开发者ID:weileng11,项目名称:KUtils-master,代码行数:27,代码来源:JsonLog.java

示例7: setToJson

import org.json.JSONArray; //导入方法依赖的package包/类
/**
 * Convert set to json array
 *
 * @param set set
 * @return converted json
 */
public static String setToJson(Set<String> set) {
    if (set == null) {
        return null;
    }
    try {
        JSONArray j = new JSONArray();
        for (String v : set) {
            j.put(v);
        }
        return j.toString();
    } catch (Throwable e) {
        e.printStackTrace();
    }
    return null;
}
 
开发者ID:yajnesh,项目名称:AndroidGeneralUtils,代码行数:22,代码来源:GenericUtil.java

示例8: printJsonLog

import org.json.JSONArray; //导入方法依赖的package包/类
/**
 * 打印格式化json字符串
 *
 * @param tag
 * @param msg
 */
private static void printJsonLog(String tag, String msg, String headString) {
    String message;
    try {
        if (msg.startsWith("{")) {
            JSONObject jsonObject = new JSONObject(msg);
            message = jsonObject.toString(JSON_INDENT);
        }
        else if (msg.startsWith("[")) {
            JSONArray jsonArray = new JSONArray(msg);
            message = jsonArray.toString(JSON_INDENT);
        }
        else {
            message = msg;
        }
    }
    catch (JSONException e) {
        message = msg;
    }
    
    printLine(tag, true);
    message = headString + LINE_SEPARATOR + message;
    String[] lines = message.split(LINE_SEPARATOR);
    for (String line : lines) {
        Log.d(tag, "║ " + line);
    }
    printLine(tag, false);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:34,代码来源:JLogUtils.java

示例9: toJson

import org.json.JSONArray; //导入方法依赖的package包/类
public String toJson() {
    JSONArray jsonItems = new JSONArray();

    for (JSONArray item : mItems.values()) {
        jsonItems.put(item);
    }
    return jsonItems.toString();
}
 
开发者ID:cleaninsights,项目名称:cleaninsights-android-sdk,代码行数:9,代码来源:EcommerceItems.java

示例10: saveCreditCard

import org.json.JSONArray; //导入方法依赖的package包/类
public void saveCreditCard(JSONArray array) {
    try {
        JSONArray localArray = getLocalCreditCardList();
        if (null != localArray) {
            for (int i = 0; i < array.length(); i++) {
                boolean isSame = false;
                JSONObject objI = array.getJSONObject(i);

                for (int j = 0; j < localArray.length(); j++) {
                    JSONObject objJ = localArray.getJSONObject(j);
                    String localCardNum = objI.optString(CreditCardConstants.KEY_CREDIT_CARD_NUMBER);
                    if (localCardNum != null && localCardNum.equalsIgnoreCase(objJ.optString(CreditCardConstants.KEY_CREDIT_CARD_NUMBER))) {
                        isSame = true;
                        break;
                    }
                }

                if (!isSame) {
                    localArray.put(objI);
                }
            }
        } else {
            localArray = array;
        }
        String saveString = localArray.toString();
        // DataEngine.getInstance().setSharedPreferenceCache(saveString);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putString(KEY_CREDIT_CARDS, saveString);
        editor.commit();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
开发者ID:MarcusMa,项目名称:MyCreditCardDemo,代码行数:34,代码来源:SharedPreferenceHelper.java

示例11: _getText

import org.json.JSONArray; //导入方法依赖的package包/类
@Override public String _getText() {
    int nitems = getCount();
    JSONArray r = new JSONArray();
    for (int i = 0; i < nitems; i++) {
        r.put(new JTableHeaderItemJavaElement(this, i)._getText());
    }
    return r.toString();
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:9,代码来源:JTableHeaderJavaElement.java

示例12: serializeFingerprintsToJson

import org.json.JSONArray; //导入方法依赖的package包/类
public static String serializeFingerprintsToJson(List<NFFTFingerprint> fingerprints) throws JSONException {
    JSONArray jsonArray = new JSONArray();
    for(NFFTFingerprint fingerprint : fingerprints){
        JSONObject fingerprintJSON = new JSONObject();
        fingerprintJSON.put("f1", fingerprint.f1);
        fingerprintJSON.put("f2", fingerprint.f2);
        fingerprintJSON.put("t1", fingerprint.t1);
        fingerprintJSON.put("t2", fingerprint.t2);
        fingerprintJSON.put("f1e", fingerprint.f1Estimate);
        fingerprintJSON.put("f2e", fingerprint.f2Estimate);
        jsonArray.put(fingerprintJSON);
    }
    return jsonArray.toString();
}
 
开发者ID:JorenSix,项目名称:Panako,代码行数:15,代码来源:PanakoWebserviceClient.java

示例13: handleResponse

import org.json.JSONArray; //导入方法依赖的package包/类
private static void handleResponse(AccessTokenAppIdPair accessTokenAppId, Request request, Response response,
        SessionEventsState sessionEventsState, FlushStatistics flushState) {
    FacebookRequestError error = response.getError();
    String resultDescription = "Success";

    FlushResult flushResult = FlushResult.SUCCESS;

    if (error != null) {
        final int NO_CONNECTIVITY_ERROR_CODE = -1;
        if (error.getErrorCode() == NO_CONNECTIVITY_ERROR_CODE) {
            resultDescription = "Failed: No Connectivity";
            flushResult = FlushResult.NO_CONNECTIVITY;
        } else {
            resultDescription = String.format("Failed:\n  Response: %s\n  Error %s",
                    response.toString(),
                    error.toString());
            flushResult = FlushResult.SERVER_ERROR;
        }
    }

    if (Settings.isLoggingBehaviorEnabled(LoggingBehavior.APP_EVENTS)) {
        String eventsJsonString = (String) request.getTag();
        String prettyPrintedEvents;

        try {
            JSONArray jsonArray = new JSONArray(eventsJsonString);
            prettyPrintedEvents = jsonArray.toString(2);
        } catch (JSONException exc) {
            prettyPrintedEvents = "<Can't encode events for debug logging>";
        }

        Logger.log(LoggingBehavior.APP_EVENTS, TAG,
                "Flush completed\nParams: %s\n  Result: %s\n  Events JSON: %s",
                request.getGraphObject().toString(),
                resultDescription,
                prettyPrintedEvents);
    }

    sessionEventsState.clearInFlightAndStats(error != null);

    if (flushResult == FlushResult.NO_CONNECTIVITY) {
        // We may call this for multiple requests in a batch, which is slightly inefficient since in principle
        // we could call it once for all failed requests, but the impact is likely to be minimal.
        // We don't call this for other server errors, because if an event failed because it was malformed, etc.,
        // continually retrying it will cause subsequent events to not be logged either.
        PersistedEvents.persistEvents(applicationContext, accessTokenAppId, sessionEventsState);
    }

    if (flushResult != FlushResult.SUCCESS) {
        // We assume that connectivity issues are more significant to report than server issues.
        if (flushState.result != FlushResult.NO_CONNECTIVITY) {
            flushState.result = flushResult;
        }
    }
}
 
开发者ID:MobileDev418,项目名称:chat-sdk-android-push-firebase,代码行数:56,代码来源:AppEventsLogger.java

示例14: PluginResult

import org.json.JSONArray; //导入方法依赖的package包/类
public PluginResult(Status status, JSONArray message) {
    this.status = status.ordinal();
    this.messageType = MESSAGE_TYPE_JSON;
    encodedMessage = message.toString();
}
 
开发者ID:alex-shpak,项目名称:keemob,代码行数:6,代码来源:PluginResult.java

示例15: setJson

import org.json.JSONArray; //导入方法依赖的package包/类
public PostRequest setJson(JSONArray jsonArray) {
    this.content = jsonArray.toString();
    this.mediaType = MediaTypes.APPLICATION_JSON_TYPE;
    return this;
}
 
开发者ID:qiaodashaoye,项目名称:SuperHttp,代码行数:6,代码来源:PostRequest.java


注:本文中的org.json.JSONArray.toString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。