本文整理匯總了Java中org.json.JSONObject.toString方法的典型用法代碼示例。如果您正苦於以下問題:Java JSONObject.toString方法的具體用法?Java JSONObject.toString怎麽用?Java JSONObject.toString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.json.JSONObject
的用法示例。
在下文中一共展示了JSONObject.toString方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: a
import org.json.JSONObject; //導入方法依賴的package包/類
public static synchronized void a(Context context, b bVar) {
synchronized (a.class) {
try {
JSONObject jSONObject = new JSONObject();
jSONObject.put("apdid", bVar.a());
jSONObject.put("deviceInfoHash", bVar.b());
jSONObject.put("token", bVar.c());
jSONObject.put("timestamp", bVar.d());
String jSONObject2 = jSONObject.toString();
c.a(context, "vkeyid_profiles_v3", "deviceid", jSONObject2);
c.a("wxcasxx_v3", "wxcasxx", jSONObject2);
} catch (Throwable e) {
LOG.logException(e);
}
}
}
示例2: errorJSON
import org.json.JSONObject; //導入方法依賴的package包/類
/**
* Helper method for reporting errors coming off a location provider
* @param provider Indicates if this error is coming from gps or network provider
* @param error The actual error being thrown by the provider
* @return Error string
*/
public static String errorJSON(String provider, Error error) {
final JSONObject json = new JSONObject();
try {
json.put("provider", provider);
json.put("error", error.number);
json.put("msg", error.message);
}
catch (JSONException exc) {
logJSONException(exc);
}
return json.toString();
}
示例3: convertJSON
import org.json.JSONObject; //導入方法依賴的package包/類
String convertJSON(Bundle bundle) {
JSONObject json = new JSONObject();
Set<String> keys = bundle.keySet();
for (String key : keys) {
try {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
json.put(key, JSONObject.wrap(bundle.get(key)));
} else {
json.put(key, bundle.get(key));
}
} catch (JSONException e) {
return null;
}
}
return json.toString();
}
示例4: getHistoryMessagesParams
import org.json.JSONObject; //導入方法依賴的package包/類
/**
* 執行獲取曆史消息Request
*
* @param from_id
* @param num
* @return
*/
public static String getHistoryMessagesParams(int from_id, int num) {
JSONObject obj1 = new JSONObject();
try {
obj1.put(ACTION, HISTORY_MSG);
JSONObject queryObj = new JSONObject();
if (from_id > 0) {
queryObj.put(FROM_ID, from_id);
}
if (from_id > 0) {
queryObj.put(ORDER, "asc");
} else queryObj.put(ORDER, "desc");
if (num > 0) {
queryObj.put(NUM, num);
}
obj1.put(PARAMS, queryObj);
} catch (Exception e) {
e.printStackTrace();
}
return obj1.toString();
}
示例5: handlePhotosResponse
import org.json.JSONObject; //導入方法依賴的package包/類
public static Photos handlePhotosResponse(String response) {
try {
JSONObject jsonObject = new JSONObject(response);
JSONObject photosJsonObject = jsonObject.getJSONObject("photos");
String photoContent = photosJsonObject.toString();
return new Gson().fromJson(photoContent, Photos.class);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
示例6: writeHeader
import org.json.JSONObject; //導入方法依賴的package包/類
static void writeHeader(OutputStream stream, JSONObject header) throws IOException {
String headerString = header.toString();
byte[] headerBytes = headerString.getBytes();
// Write version number and big-endian header size
stream.write(HEADER_VERSION);
stream.write((headerBytes.length >> 16) & 0xff);
stream.write((headerBytes.length >> 8) & 0xff);
stream.write((headerBytes.length >> 0) & 0xff);
stream.write(headerBytes);
}
示例7: uploadContents
import org.json.JSONObject; //導入方法依賴的package包/類
public String uploadContents(String contents) throws Exception {
if (!rootJson.has("appkey") || !rootJson.has("timestamp")) {
throw new Exception("appkey, timestamp and validation_token needs to be set.");
}
// Construct the json string
JSONObject uploadJson = new JSONObject();
uploadJson.put("appkey", rootJson.getString("appkey"));
uploadJson.put("timestamp", rootJson.getString("timestamp"));
uploadJson.put("content", contents);
// Construct the request
String url = host + uploadPath;
String postBody = uploadJson.toString();
String sign = DigestUtils.md5Hex("POST" + url + postBody + appMasterSecret);
url = url + "?sign=" + sign;
HttpPost post = new HttpPost(url);
post.setHeader("User-Agent", USER_AGENT);
StringEntity se = new StringEntity(postBody, "UTF-8");
post.setEntity(se);
// Send the post request and get the response
HttpResponse response = client.execute(post);
System.out.println("Response Code : " + response.getStatusLine().getStatusCode());
BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
StringBuffer result = new StringBuffer();
String line = "";
while ((line = rd.readLine()) != null) {
result.append(line);
}
System.out.println(result.toString());
// Decode response string and get file_id from it
JSONObject respJson = new JSONObject(result.toString());
String ret = respJson.getString("ret");
if (!ret.equals("SUCCESS")) {
throw new Exception("Failed to upload file");
}
JSONObject data = respJson.getJSONObject("data");
String fileId = data.getString("file_id");
// Set file_id into rootJson using setPredefinedKeyValue
setPredefinedKeyValue("file_id", fileId);
return fileId;
}
示例8: getValueManually
import org.json.JSONObject; //導入方法依賴的package包/類
@Override
public String getValueManually(Integer contestId) {
System.out.println("Updating rating prediction for contest " + contestId + " time " + System.currentTimeMillis());
String requestURL = BACK_END_URL + "/GetNextRatingServlet?contestId=" + contestId;
try {
JSONObject json = JsonReader.read(requestURL);
return json.toString();
} catch (Exception ex) {
System.err.println("Couldn't get request results " + requestURL
+ "\n" + ex.getMessage());
}
return JSON_FAIL_STRING;
}
示例9: getVersion
import org.json.JSONObject; //導入方法依賴的package包/類
@RequestMapping(value = "/version", method = RequestMethod.GET, produces = "application/json")
@ResponseBody
public String getVersion() throws Exception {
try {
JSONObject myString = new JSONObject();
myString.put("version", "0.1");
return myString.toString();
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
示例10: satelliteDataJSON
import org.json.JSONObject; //導入方法依賴的package包/類
/**
* Converts GpsStatus into JSON.
* @param gpsStatus Send a GpsStatus whenever the GPS fires
* @return JSON representation of the satellite data
*/
public static String satelliteDataJSON(GpsStatus gpsStatus){
final Calendar calendar = Calendar.getInstance();
final JSONObject json = new JSONObject();
try {
json.put("provider", SATELLITE_PROVIDER);
json.put("timestamp", calendar.getTimeInMillis());
if(gpsStatus.getSatellites() != null) {
int count = 0;
final int timeToFirstFix = gpsStatus.getTimeToFirstFix();
for(GpsSatellite sat: gpsStatus.getSatellites() ){
final JSONObject satelliteInfo = new JSONObject();
satelliteInfo.put("PRN", sat.getPrn());
satelliteInfo.put("timeToFirstFix", timeToFirstFix);
satelliteInfo.put("usedInFix", sat.usedInFix());
satelliteInfo.put("azimuth", sat.getAzimuth());
satelliteInfo.put("elevation", sat.getElevation());
satelliteInfo.put("hasEphemeris", sat.hasEphemeris());
satelliteInfo.put("hasAlmanac", sat.hasAlmanac());
satelliteInfo.put("SNR", sat.getSnr());
json.put(Integer.toString(count), satelliteInfo);
count++;
}
}
}
catch (JSONException exc){
logJSONException(exc);
}
return json.toString();
}
示例11: toJson
import org.json.JSONObject; //導入方法依賴的package包/類
@Override
public Object toJson() throws JSONException {
if(compareType.equals(TYPE_EQUAL)) {
return value;
} else {
JSONObject root = new JSONObject();
root.put(compareType, value);
return root.toString();
}
}
示例12: constructJsonObject
import org.json.JSONObject; //導入方法依賴的package包/類
private String constructJsonObject(Cell cell, byte[] rowKey) throws UnsupportedEncodingException {
final JSONObject jo = new JSONObject();
jo.put("row_key", Bytes.toString(rowKey));
jo.put("column_family", targetCf);
jo.put("column_qualifier", Bytes.toString(CellUtil.cloneQualifier(cell)));
jo.put("column_value", Bytes.toString(sendValue ? CellUtil.cloneValue(cell) : new byte[]{}));
jo.put("secondary_index", secondaryIndexTable);
jo.put("secondary_index_cf", secondaryIndexCF);
jo.put("destination_table", destinationTable);
return jo.toString();
}
示例13: serialize
import org.json.JSONObject; //導入方法依賴的package包/類
private static String serialize(PhoneFinderConfig config) throws JSONException {
JSONObject object = new JSONObject();
object.put(FIELD_ACTIVATED, config.isAppEnabled());
object.put(FIELD_FINDER_DELAY, config.getDelayTime());
if( config.getVolume() != null ) {
object.put(FIELD_FINDER_VOLUME, config.getVolume().intValue());
}
return object.toString(1);
}
示例14: isSystemReady
import org.json.JSONObject; //導入方法依賴的package包/類
@RequestMapping(value = "/isSystemReady", method = RequestMethod.GET)
public String isSystemReady() {
JSONObject response = new JSONObject();
response.put("isSystemReady", SystemManager.IS_SYSTEM_READY.get());
return response.toString();
}
示例15: callDeleteWebServiceProcess
import org.json.JSONObject; //導入方法依賴的package包/類
private void callDeleteWebServiceProcess(JSONObject jbObject) {
showProgress();
String jsonData = jbObject.toString();
new Webservice(this, Vars.webMethodName.get(15)).execute(jsonData, Vars.gateKeperHit, Vars.webMethodName.get(15));
}