本文整理汇总了Java中org.json.JSONArray.put方法的典型用法代码示例。如果您正苦于以下问题:Java JSONArray.put方法的具体用法?Java JSONArray.put怎么用?Java JSONArray.put使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.json.JSONArray
的用法示例。
在下文中一共展示了JSONArray.put方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handle
import org.json.JSONArray; //导入方法依赖的package包/类
@Override
public void handle(RoutingContext ctx) {
JSONArray response = new JSONArray();
String clientId = UserManager.getEncryptedIdFromSession(ctx);
ResultSet rs = MySQL.executeQuery("SELECT * FROM travel_clients INNER JOIN travel_list USING(topic) WHERE client_id=?", clientId);
try {
while(rs != null && rs.next()) {
JSONObject travelRoom = new JSONObject();
travelRoom.put("topic", rs.getString("topic"));
travelRoom.put("title", rs.getString("title"));
response.put(travelRoom);
}
} catch (SQLException e) {
e.printStackTrace();
}
if(response.length() == 0) {
ctx.response().setStatusCode(204).end();
ctx.response().close();
} else {
ctx.response().setStatusCode(200);
ctx.response().end(response.toString());
ctx.response().close();
}
}
示例2: encodingArray
import org.json.JSONArray; //导入方法依赖的package包/类
private static JSONArray encodingArray(Object array){
JSONArray jsonArray=new JSONArray();
if(!array.getClass().isArray()) return jsonArray;
final int length = Array.getLength(array);
for(int i=0;i<length;i++){
try {
Object item = Array.get(array,i);
JsonEncodeType type=getEncodingType(item);
//LogUtil.e("json","name="+i+",value="+item+",array="+array.toString());
if(JsonEncodeType.Normal == type){
jsonArray.put(i,item);
}else if(JsonEncodeType.List == type){
jsonArray.put(i, encodingList(item));
}else if(JsonEncodeType.Array == type){
jsonArray.put(i, encodingArray(item));
}else if(JsonEncodeType.Map == type){
jsonArray.put(i, encodingMap(item));
}else {
jsonArray.put(i,encodingObject(item));
}
}catch (JSONException ex){
LogUtils.e(ex);
}
}
return jsonArray;
}
示例3: stopLocationJSON
import org.json.JSONArray; //导入方法依赖的package包/类
/**
* Attempt to gracefully stop all available location providers.
* Be sure to also check for error events.
* @return A JSONObject containing an array that lists each provider and boolean indicating
* whether or not the stop location attempt was successful.
*/
public static String stopLocationJSON(List<StopLocation> stopLocation) {
final JSONArray jsonArray = new JSONArray();
final JSONObject stopLocationDetails = new JSONObject();
try {
for (int i = 0; i < stopLocation.size(); i++){
final JSONObject json = new JSONObject();
json.put("provider", stopLocation.get(i).provider);
json.put("success", stopLocation.get(i).success);
jsonArray.put(json);
}
stopLocationDetails.put("stopLocation", jsonArray);
}
catch( JSONException exc) {
logJSONException(exc);
}
return stopLocationDetails.toString();
}
示例4: toJSON
import org.json.JSONArray; //导入方法依赖的package包/类
public static JSONObject toJSON(View view) throws JSONException {
UiThreadUtil.assertOnUiThread();
JSONObject result = new JSONObject();
result.put("n", view.getClass().getName());
result.put("i", System.identityHashCode(view));
Object tag = view.getTag();
if (tag != null && tag instanceof String) {
result.put("t", tag);
}
if (view instanceof ViewGroup) {
ViewGroup viewGroup = (ViewGroup) view;
if (viewGroup.getChildCount() > 0) {
JSONArray children = new JSONArray();
for (int i = 0; i < viewGroup.getChildCount(); i++) {
children.put(i, toJSON(viewGroup.getChildAt(i)));
}
result.put("c", children);
}
}
return result;
}
示例5: collection2Json
import org.json.JSONArray; //导入方法依赖的package包/类
public static JSONArray collection2Json(Collection<?> data) {
JSONArray jsonArray = new JSONArray();
if (data != null) {
for (Object aData : data) {
jsonArray.put(wrap(aData));
}
}
return jsonArray;
}
示例6: get
import org.json.JSONArray; //导入方法依赖的package包/类
@Nullable
public synchronized String get(@NonNull BaseCollectionSubscription subscription) throws IOException, JSONException, NoSuchAlgorithmException {
if(!mEnabled)
return null;
String fingerprint = subscription.getFingerprint();
DiskLruCache.Snapshot record = mCache.get(fingerprint);
if(record != null) {
InputStream inputstream = record.getInputStream(DEFAULT_INDEX);
byte[] rec = StreamUtility.toByteArray(inputstream);
String jsonValue = XorUtility.xor(rec, subscription.getAuthToken());
Logcat.d("Reading from subscription cache. key=%s; value=%s", fingerprint, jsonValue);
JSONArray documentIdArray = new JSONArray(jsonValue);
JSONArray documentArray = new JSONArray();
for(int i = 0; i < documentIdArray.length(); i++) {
String document = getDocument(subscription, documentIdArray.optString(i));
if(document == null) {
return null;
}
documentArray.put(new JSONObject(document));
}
return documentArray.toString();
}
Logcat.d("Reading from disk subscription cache. key=%s; value=null", fingerprint);
return null;
}
示例7: createDevicePostData
import org.json.JSONArray; //导入方法依赖的package包/类
private Map<String, JSONObject> createDevicePostData(List<HealthRecordBean> healthRecordsList) throws JSONException {
Map<String, JSONObject> healthDataJson = new HashMap<>();
for (int i = 0; i < healthRecordsList.size(); i++) {
HealthRecordBean healthRecord = healthRecordsList.get(i);
String dataType = healthRecord.getDataType();
if (!healthDataJson.containsKey(dataType)) {
String date = new SimpleDateFormat("YYYY-MM-DD").format(new Date());
JSONObject dataTypeJsonObject = new JSONObject();
dataTypeJsonObject.put(Constants.DATA_TYPE,dataType);
dataTypeJsonObject.put(Constants.DEVICE_ID, healthRecord.getDeviceID());
dataTypeJsonObject.put(Constants.DEVICE_NAME, healthRecord.getDeviceName());
dataTypeJsonObject.put(Constants.USER_DEVICE_ID, healthRecord.getUserDeviceID());
dataTypeJsonObject.put(Constants.PROVIDER_ID, tempProviderId);
dataTypeJsonObject.put(Constants.DATE, date);
dataTypeJsonObject.put(Constants.DATA, new JSONArray());
healthDataJson.put(dataType, dataTypeJsonObject);
}
JSONArray dataArray = healthDataJson.get(dataType).getJSONArray(Constants.DATA);
JSONObject itemJson = new JSONObject(healthRecord.getData());
itemJson.put(Constants.TIME, healthRecord.getTime());
dataArray.put(itemJson);
}
return healthDataJson;
}
示例8: loadNewsListFromLocal
import org.json.JSONArray; //导入方法依赖的package包/类
/**
* 从本地缓存加载资讯数据列表
*
* @param classid 分类id
* @param newsListCallback 资讯列表回调
*/
public void loadNewsListFromLocal(String classid, final NewsListCallback newsListCallback) {
int preCount = 0;
int oneCount = 20;
JSONArray jsonArray = new JSONArray();
// 其他分类
List<NewsListOtherCache> otherCaches = DataSupport.order("id asc").where("classid = ?", classid).limit(oneCount).offset(preCount).find(NewsListOtherCache.class);
for (NewsListOtherCache otherCache :
otherCaches) {
try {
JSONObject jsonObject = new JSONObject(otherCache.getNews());
jsonArray.put(jsonObject);
} catch (JSONException e) {
e.printStackTrace();
newsListCallback.onError("数据解析失败");
break;
}
}
if (jsonArray.length() > 0) {
newsListCallback.onSuccess(jsonArray);
LogUtils.d(TAG, "加载到缓存其他分类数据 = " + jsonArray.toString());
} else {
newsListCallback.onError("没有本地数据");
}
}
示例9: handle
import org.json.JSONArray; //导入方法依赖的package包/类
@Override
public void handle(RoutingContext ctx) {
try {
ResultSet rs = DB.executeQuery("SELECT * FROM afterschool_items");
JSONArray response = new JSONArray();
while (rs.next()) {
JSONObject afterschool = new JSONObject();
afterschool.put("no", rs.getInt("no"));
afterschool.put("title", rs.getString("title"));
afterschool.put("target", rs.getInt("target"));
afterschool.put("on_monday", rs.getBoolean("on_monday"));
afterschool.put("on_tuesday", rs.getBoolean("on_tuesday"));
afterschool.put("on_saturday", rs.getBoolean("on_saturday"));
response.put(afterschool);
}
if(response.length() != 0) {
ctx.response().setStatusCode(200);
ctx.response().end(response.toString());
ctx.response().close();
} else {
ctx.response().setStatusCode(204).end();
ctx.response().close();
}
} catch (SQLException e) {
Log.l("SQLException");
}
}
示例10: add
import org.json.JSONArray; //导入方法依赖的package包/类
/**
* Add Domain with column, operator and it's condition value
*
* @param column column name
* @param operator conditional operator
* @param value condition value
* @return self object
*/
public ODomain add(String column, String operator, Object value) {
JSONArray domain = new JSONArray();
domain.put(column);
domain.put(operator);
if (value instanceof List) {
domain.put(listToArray(value));
} else {
domain.put(value);
}
add(domain);
return this;
}
示例11: modelsToJSON
import org.json.JSONArray; //导入方法依赖的package包/类
public static JSONArray modelsToJSON(
@SuppressWarnings("rawtypes") List models, Mapper mapper)
throws IllegalAccessException, NoSuchFieldException, JSONException,
NoSuchMethodException, InvocationTargetException {
JSONArray jsonArray = new JSONArray();
for (Object model : models) {
jsonArray.put(modelToJSON((Model) model, mapper));
}
return jsonArray;
}
示例12: put
import org.json.JSONArray; //导入方法依赖的package包/类
public void put(String key, String[] array) {
try {
JSONArray jsonArray = new JSONArray();
for (int i = 0; i < array.length; i++) {
jsonArray.put(i, array[i]);
}
data.put(key, jsonArray);
} catch (JSONException e) {
}
}
示例13: doGet
import org.json.JSONArray; //导入方法依赖的package包/类
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
resp.setCharacterEncoding("utf-8");
HashMap<String, Object> status = new HashMap<>();
JSONArray allNameAndBrief = new JSONArray();
JSONObject thisNameAndBrief = new JSONObject();
JSONObject object = new JSONObject();
// build main data
for (Object o : allQuizForm.entrySet()) {
Map.Entry entry = (Map.Entry) o;
QuizForm val = (QuizForm) entry.getValue();
thisNameAndBrief.put("name", val.getQuizFormName());
thisNameAndBrief.put("brief", val.getQuizFormBrief());
allNameAndBrief.put(thisNameAndBrief);
}
// build status
status.put("code", String.valueOf(HttpServletResponse.SC_OK));
status.put("message", "query all quiz form info successful");
status.put("extra", Constant.JSON.EMPTY_OBJECT);
status.put("security", Constant.JSON.EMPTY_OBJECT);
// build object
object.put("meta", status);
object.put("data", allNameAndBrief);
// FIXME 非测试时移去注释 (配合Configuration System把这里设计的合理一点 - 磷)
// response.setContentType("application/json"); // specific content type
try (ServletOutputStream out = resp.getOutputStream()) {
out.write(resp.toString().getBytes(StandardCharsets.UTF_8));
out.flush();
} catch (IOException e) {
LoggerFactory.getLogger(Counter.class).error("IOException thrown: ", e);
}
}
示例14: getJson
import org.json.JSONArray; //导入方法依赖的package包/类
protected JSONArray getJson(Collection<?> coll) throws JSONException {
JSONArray jsonArray = new JSONArray();
for (Object o : coll) {
o = getJsonObject(o);
if (o != null)
jsonArray.put(o);
}
return jsonArray;
}
示例15: getWholeDbAsJson
import org.json.JSONArray; //导入方法依赖的package包/类
public static String getWholeDbAsJson(final List<Long> vehicleIds, final Context context) {
JSONObject result = new JSONObject();
JSONArray vehicles = new JSONArray();
try {
for (Long vehicleId : vehicleIds) {
JSONObject vehicle = new JSONObject();
vehicle.put(JSON_VEHICLE, getVehicleAsJson(vehicleId, context));
vehicle.put(FillUpEntry.TABLE_NAME, getFillUps(vehicleId, context));
vehicle.put(ExpenseEntry.TABLE_NAME, getExpenses(vehicleId, context));
vehicles.put(vehicle);
}
result.put(JSON_DATE, new Date());
result.put(JSON_DEVICE_APP_INSTANCE, InstanceID.getInstance(context).getId());
result.put(VehicleEntry.TABLE_NAME, vehicles);
result.put(VehicleTypeEntry.TABLE_NAME, getVehicleTypes(context));
} catch (JSONException e) {
Log.e(LOG_TAG, "Error while creating JSON representation of DB.", e);
return null;
}
return result.toString();
}