本文整理汇总了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();
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例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);
}
示例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();
}
示例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();
}
}
示例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();
}
示例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();
}
示例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;
}
}
}
示例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();
}
示例15: setJson
import org.json.JSONArray; //导入方法依赖的package包/类
public PostRequest setJson(JSONArray jsonArray) {
this.content = jsonArray.toString();
this.mediaType = MediaTypes.APPLICATION_JSON_TYPE;
return this;
}