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


Java JSONArray.put方法代码示例

本文整理汇总了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();
	}
}
 
开发者ID:JoMingyu,项目名称:Daejeon-People,代码行数:29,代码来源:TravelList.java

示例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;
}
 
开发者ID:A-Miracle,项目名称:QiangHongBao,代码行数:27,代码来源:JsonUtils.java

示例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();
}
 
开发者ID:SUTFutureCoder,项目名称:localcloud_fe,代码行数:28,代码来源:JSONHelper.java

示例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;
}
 
开发者ID:qq565999484,项目名称:RNLearn_Project1,代码行数:25,代码来源:ViewHierarchyDumper.java

示例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;
}
 
开发者ID:jeasinlee,项目名称:AndroidBasicLibs,代码行数:10,代码来源:JsonUtils.java

示例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;
}
 
开发者ID:rapid-io,项目名称:rapid-io-android,代码行数:27,代码来源:SubscriptionDiskCache.java

示例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;
}
 
开发者ID:Welloculus,项目名称:MobileAppForPatient,代码行数:25,代码来源:PostDataService.java

示例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("没有本地数据");
    }

}
 
开发者ID:6ag,项目名称:LiuAGeAndroid,代码行数:34,代码来源:NewsDALManager.java

示例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");
	}
}
 
开发者ID:DSM-DMS,项目名称:DMS,代码行数:32,代码来源:LoadItemList.java

示例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;
}
 
开发者ID:odoo-mobile-intern,项目名称:odoo-work,代码行数:21,代码来源:ODomain.java

示例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;
}
 
开发者ID:sergueik,项目名称:SWET,代码行数:11,代码来源:UtilExtensions.java

示例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) {

	}
}
 
开发者ID:G2159687,项目名称:ESPD,代码行数:12,代码来源:Bundle.java

示例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);
	}
}
 
开发者ID:ProgramLeague,项目名称:strictfp-back-end,代码行数:33,代码来源:GetQuiz.java

示例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;
}
 
开发者ID:limberest,项目名称:limberest,代码行数:10,代码来源:Jsonator.java

示例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();
    }
 
开发者ID:piskula,项目名称:FuelUp,代码行数:28,代码来源:JsonUtil.java


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