當前位置: 首頁>>代碼示例>>Java>>正文


Java JSONObject.numberToString方法代碼示例

本文整理匯總了Java中org.json.JSONObject.numberToString方法的典型用法代碼示例。如果您正苦於以下問題:Java JSONObject.numberToString方法的具體用法?Java JSONObject.numberToString怎麽用?Java JSONObject.numberToString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.json.JSONObject的用法示例。


在下文中一共展示了JSONObject.numberToString方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: writeValue

import org.json.JSONObject; //導入方法依賴的package包/類
/**
 * Write a value.
 * 
 * @param value
 *            One of these types: Boolean, Number, etc.
 * @throws JSONException
 */
private void writeValue(Object value) throws JSONException {
    if (value instanceof Number) {
        String string = JSONObject.numberToString((Number) value);
        int integer = this.values.find(string);
        if (integer != none) {
            write(2, 2);
            writeAndTick(integer, this.values);
            return;
        }
        if (value instanceof Integer || value instanceof Long) {
            long longer = ((Number) value).longValue();
            if (longer >= 0 && longer < int14) {
                write(0, 2);
                if (longer < int4) {
                    zero();
                    write((int) longer, 4);
                    return;
                }
                one();
                if (longer < int7) {
                    zero();
                    write((int) longer, 7);
                    return;
                }
                one();
                write((int) longer, 14);
                return;
            }
        }
        write(1, 2);
        for (int i = 0; i < string.length(); i += 1) {
            write(bcd(string.charAt(i)), 4);
        }
        write(endOfNumber, 4);
        this.values.register(string);
    } else {
        write(3, 2);
        writeJSON(value);
    }
}
 
開發者ID:jalian-systems,項目名稱:marathonv5,代碼行數:48,代碼來源:Compressor.java

示例2: writeValue

import org.json.JSONObject; //導入方法依賴的package包/類
/**
 * Write a value.
 *
 * @param value
 *            One of these types: Boolean, Number, etc.
 * @throws JSONException
 */
private void writeValue(Object value) throws JSONException {
    if (value instanceof Number) {
        String string = JSONObject.numberToString((Number) value);
        int integer = this.values.find(string);
        if (integer != none) {
            write(2, 2);
            writeAndTick(integer, this.values);
            return;
        }
        if (value instanceof Integer || value instanceof Long) {
            long longer = ((Number) value).longValue();
            if (longer >= 0 && longer < int14) {
                write(0, 2);
                if (longer < int4) {
                    zero();
                    write((int) longer, 4);
                    return;
                }
                one();
                if (longer < int7) {
                    zero();
                    write((int) longer, 7);
                    return;
                }
                one();
                write((int) longer, 14);
                return;
            }
        }
        write(1, 2);
        for (int i = 0; i < string.length(); i += 1) {
            write(bcd(string.charAt(i)), 4);
        }
        write(endOfNumber, 4);
        this.values.register(string);
    } else {
        write(3, 2);
        writeJSON(value);
    }
}
 
開發者ID:starn,項目名稱:encdroidMC,代碼行數:48,代碼來源:Compressor.java

示例3: getJsonRepresentation

import org.json.JSONObject; //導入方法依賴的package包/類
public static String getJsonRepresentation(Object value) throws JSONException {
  if (value == null || value.equals(null)) {
    return "null";
  }
  if (value instanceof FString) {
    return JSONObject.quote(value.toString());
  }
  if (value instanceof YailList) {
    return ((YailList) value).toJSONString();
  }
  // The Json tokener used in getObjectFromJson cannot handle
  // fractions.  So we Json encode fractions by first converting
  // them to doubles. This is an example of value with Kawa type any
  // being exposed to the rest of App Inventor by the value being
  // passed to a component method, in this case TinyDB or TinyWebDB
  // StoreValue.  See the "warning" comment in runtime.scm at
  // call-component-method.
  if (value instanceof IntFraction) {
    return JSONObject.numberToString((Number) ((IntFraction)value).doubleValue());
  }
  if (value instanceof Number) {
    return JSONObject.numberToString((Number) value);
  }
  if (value instanceof Boolean) {
    return value.toString();
  }
  if (value instanceof List) {
    value = ((List)value).toArray();
  }
  if (value.getClass().isArray()) {
    StringBuilder sb = new StringBuilder();
    sb.append("[");
    String separator = "";
    for (Object o: (Object[]) value) {
      sb.append(separator).append(getJsonRepresentation(o));
      separator = ",";
    }
    sb.append("]");
    return sb.toString();
  }
  return JSONObject.quote(value.toString());
}
 
開發者ID:mit-cml,項目名稱:appinventor-extensions,代碼行數:43,代碼來源:JsonUtil.java


注:本文中的org.json.JSONObject.numberToString方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。