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


Java JSONObject.length方法代码示例

本文整理汇总了Java中org.json.JSONObject.length方法的典型用法代码示例。如果您正苦于以下问题:Java JSONObject.length方法的具体用法?Java JSONObject.length怎么用?Java JSONObject.length使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.json.JSONObject的用法示例。


在下文中一共展示了JSONObject.length方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: parseJsonSearch

import org.json.JSONObject; //导入方法依赖的package包/类
private void parseJsonSearch(String result){
    try {
        JSONArray jArray = new JSONArray(result);
        GroupBean gb = null;
        for (int i = 0; i < jArray.length(); i++) {
            JSONObject json = jArray.getJSONObject(i);
            if(json.length()==0){
                return;
            }
            gb = new GroupBean();
            gb.setmGroupName(json.getString("GROUPNAME"));
            gb.setmGroupId(json.getString("GROUPID"));
            gb.setmGroupTag(json.getString("TAGNAME"));
            gb.setmGroupDesc(json.getString("DESCRITION"));
            gb.setmPhoto(json.getString("GROUPPHOTO"));
            gb.setmGroupAdmin("2");
            gb.setmGroupAccessType(json.getString("GROUPACCESSTYPE"));
            tbList.add(gb);
        }
        setAdapter();
    } catch (Exception e) {
        // TODO: handle exception
        //Log.e("Errror", "error"+e.getMessage());
        e.printStackTrace();
    }
}
 
开发者ID:mityung,项目名称:XERUNG,代码行数:27,代码来源:PublicDirectory.java

示例2: writeFilterSection

import org.json.JSONObject; //导入方法依赖的package包/类
private void writeFilterSection(JSONObject jQuery, LocationsSearchFilter query)
{
	JSONObject jFilter = new JSONObject(true);
	if (query.getCategoryGroupIds() != null)
		jFilter.put("category_group_ids", new JSONArray(query.getCategoryGroupIds()));
	if (query.getCategoryIds() != null)
		jFilter.put("category_ids", new JSONArray(query.getCategoryIds()));
	if (!Helper.isEmpty(query.getName()))
		jFilter.put("name", query.getName());
	if (!Helper.isEmpty(query.getWheelchair()))
		jFilter.put("wheelchair", query.getWheelchair());
	if (!Helper.isEmpty(query.getSmoking()))
		jFilter.put("smoking", query.getSmoking());
	if (query.getFee() != null)
		jFilter.put("fee", query.getFee());

	if (jFilter.length() > 0)
		jQuery.put("filter", jFilter);
}
 
开发者ID:GIScience,项目名称:openrouteservice,代码行数:20,代码来源:JsonLocationsRequestProcessor.java

示例3: handleData

import org.json.JSONObject; //导入方法依赖的package包/类
private void handleData (Map<String, String> data) {
	// TODO: Perform some action now..!
	// ...

	JSONObject jobject = new JSONObject();

	try {
		for (Map.Entry<String, String> entry : data.entrySet()) {
			jobject.put(entry.getKey(), entry.getValue());
		}
	} catch (JSONException e) { Utils.d("JSONException: parsing, " + e.toString()); }

	if (jobject.length() > 0) {
		KeyValueStorage.setValue("firebase_notification_data", jobject.toString());
	}
}
 
开发者ID:FrogSquare,项目名称:GodotFireBase,代码行数:17,代码来源:MessagingService.java

示例4: toMap

import org.json.JSONObject; //导入方法依赖的package包/类
/**
 * Convert JSON object (map) to the respective Java types.
 *
 * @param type the map object type
 * @param jMap the JSON object map
 * @return the map of values as Java objects
 * @throws JSONException
 */
private static Map<Object, Object> toMap(final MapType type, final JSONObject jMap)
    throws JSONException {
  final Map<Object, Object> map = new LinkedHashMap<>(jMap.length());
  Iterator itr = jMap.keys();
  String key;
  while (itr.hasNext()) {
    key = (String) itr.next();
    map.put(jsonToObject(key, type.getTypeOfKey()),
        jsonToObject(jMap.get(key), type.getTypeOfValue()));
  }
  return map;
}
 
开发者ID:ampool,项目名称:monarch,代码行数:21,代码来源:TypeUtils.java

示例5: jsonToMap

import org.json.JSONObject; //导入方法依赖的package包/类
private static Map<String, String> jsonToMap(JSONArray array, String keyName, String valueName) throws JSONException {
    Map<String, String> map = new HashMap<>();
    if (array == null) {
        return map;
    }
    for (int i = 0; i < array.length(); i++) {
        JSONObject obj = array.getJSONObject(i);
        if (obj.length() != 2) {
            throw new IllegalStateException("Array object not a key/value object. Has " + obj.length() + " fields");
        }
        map.put(obj.getString(keyName), obj.getString(valueName));
    }
    return map;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:15,代码来源:LookupUserIdResponse.java

示例6: PurchaseSalesOrderConfig

import org.json.JSONObject; //导入方法依赖的package包/类
public PurchaseSalesOrderConfig(JSONObject jsonObject) {
  if (jsonObject != null && jsonObject.length() > 0) {
    try {
      JSONArray jsonArray = jsonObject.getJSONArray(ENTITY_TAGS);
      et = new ArrayList<>();
      for (int i = 0; i < jsonArray.length(); i++) {
        Object obj = jsonArray.get(i);
        et.add((String) obj);
      }

    } catch (JSONException e) {
      et = new ArrayList<>(1);
    }

    if (jsonObject.get(SALES_ORDER_APPROVAL) != null) {
      soa = jsonObject.getBoolean(SALES_ORDER_APPROVAL);
    }
    if (jsonObject.get(PURCHASE_ORDER_APPROVAL) != null) {
      poa = jsonObject.getBoolean(PURCHASE_ORDER_APPROVAL);
    }
    if (jsonObject.get(SALES_ORDER_APPROVAL_CREATION) != null) {
      soac = jsonObject.getBoolean(SALES_ORDER_APPROVAL_CREATION);
    }
    if (jsonObject.get(SALES_ORDER_APPROVAL_SHIPPING) != null) {
      soas = jsonObject.getBoolean(SALES_ORDER_APPROVAL_SHIPPING);
    }
  }
}
 
开发者ID:logistimo,项目名称:logistimo-web-service,代码行数:29,代码来源:ApprovalsConfig.java

示例7: getListTypeAndModel

import org.json.JSONObject; //导入方法依赖的package包/类
/**
 * Function which get a list all type and model saved in the database
 * @version 1.00
 * 
 */	
public void getListTypeAndModel(ArrayList<Equipment> listTypeAndModel)
{
	String url ="http://"+SERVER_NAME+":"+PORT_NUMBER+"/equipments/list";

	GetData getSPs = new GetData();		
	JSONArray json = getSPs.Start(url);	

	for(int i=0;i<json.length();i++)
	{
		try 
		{	
			JSONObject jsonObject = json.getJSONObject(i);
	
			if(jsonObject.length()>0)
			{
				listTypeAndModel.add(i,new Equipment());
				
				listTypeAndModel.get(i).setID( jsonObject.getInt("id"));
				listTypeAndModel.get(i).setType(jsonObject.getString("type"));
				listTypeAndModel.get(i).setModel(jsonObject.getString("model"));

			}
		} 
		
		catch (JSONException e) 
		{				
			e.printStackTrace();
		}	
	}	
}
 
开发者ID:Will30,项目名称:MonitorYourLAN,代码行数:36,代码来源:Equipment.java

示例8: getMoreInfoforSP

import org.json.JSONObject; //导入方法依赖的package包/类
/**
 * Get more info about a strategic point and defines if strategic point is an equipment, network or datastorage
 * @since 1.01	 
 */
public void getMoreInfoforSP()
{
	
	String url ="http://"+SERVER_NAME+":"+PORT_NUMBER+"/SPs/"+this.getID();

	GetData getSPs = new GetData();		
	JSONArray json = getSPs.Start(url);	
		
	for(int i=0;i<json.length();i++)
	{
		try 
		{	
			JSONObject jsonObject = json.getJSONObject(i);
	
			if(jsonObject.length()>0)
			{
				this.setName(jsonObject.getString("name"));
				this.setDescription(jsonObject.getString("Description")); 
				this.setLocation(jsonObject.getString("location"));
				this.setIcon(jsonObject.getString("icon")); 
				this.setIPAddress(jsonObject.getString("IPaddress")); 
				this.getService().setID((byte) jsonObject.getInt("id_Service")); 
			
				this.getLed().setID((byte)jsonObject.getInt("id_LED"));
				this.getLed().setColor(jsonObject.getString("color"));
				this.getLed().setUNC(jsonObject.getString("UNC"));
			}
		} 
		
		catch (JSONException e) 
		{				
			e.printStackTrace();
		}	
	}		
}
 
开发者ID:Will30,项目名称:MonitorYourLAN,代码行数:40,代码来源:StrategicPoint.java

示例9: getAllUsers

import org.json.JSONObject; //导入方法依赖的package包/类
/**
 * Get all users from database
 * @version 1.00
 * @param listUsers instanced to null into Controller 
 */

public void getAllUsers(ArrayList<User> listUsers)
{
	String url ="http://"+StrategicPoint.SERVER_NAME+":"+StrategicPoint.PORT_NUMBER+"/users/";

	GetData getSPs = new GetData();
	
	JSONArray json = getSPs.Start(url);	
	System.out.println("UsergetAllUsers() : Taille Json -->"+json.length());
	
	for(int i=0;i<json.length();i++)
	{
		try 
		{
			
			JSONObject jsonObject = json.getJSONObject(i);
			if(jsonObject.length()>0)
			{
				listUsers.add(i, new User());
							
				listUsers.get(i).setID( (byte) jsonObject.getInt("id"));
				listUsers.get(i).setUsername(jsonObject.getString("username"));
				listUsers.get(i).setPassword(jsonObject.getString("password"));
				listUsers.get(i).setEmail(jsonObject.getString("email"));
				listUsers.get(i).setAdminAccess((byte)jsonObject.getInt("adminAccess"));
				listUsers.get(i).setMailReceived((byte)jsonObject.getInt("emailReceived"));
				listUsers.get(i).setAccountEnable((byte)jsonObject.getInt("accountEnable"));
				listUsers.get(i).setIDservice( (byte) jsonObject.getInt("id_Service"));	
		
			}
		} 
		
		catch (JSONException e) 
		{				
			e.printStackTrace();
		}	
	}	
	
}
 
开发者ID:Will30,项目名称:MonitorYourLAN,代码行数:45,代码来源:User.java

示例10: getPropertyMap

import org.json.JSONObject; //导入方法依赖的package包/类
private Map<QName, String> getPropertyMap(JSONObject properties) throws Exception
{
    Map<QName, String> propertyMap = new HashMap<QName, String>(properties.length());
    @SuppressWarnings("rawtypes")
    Iterator propNames = properties.keys();
    while(propNames.hasNext())
    {
        String propName = (String)propNames.next();
        String value = properties.getString(propName);

        propertyMap.put(QName.resolveToQName(namespaceService, propName), value);
    }

    return propertyMap;
}
 
开发者ID:Alfresco,项目名称:alfresco-remote-api,代码行数:16,代码来源:SOLRWebScriptTest.java

示例11: parseJson

import org.json.JSONObject; //导入方法依赖的package包/类
private void parseJson(String result){	
	try {
		hideMainScreen();
		hideSearchProgress();
		clearPreviousData();
		JSONArray jArray = new JSONArray(result);
		GroupBean gb = null;
		for (int i = 0; i < jArray.length(); i++) {
			JSONObject json = jArray.getJSONObject(i);
			if(json.length()==0){
				showServerResult("No record found.");
				return;
			}
			gb = new GroupBean();
			gb.setmGroupName(json.getString("GROUPNAME"));
			gb.setmGroupId(json.getString("GROUPID"));
			gb.setmGroupTag(json.getString("TAGNAME"));
			gb.setmGroupDesc(json.getString("DESCRITION"));
			gb.setmPhoto(json.getString("GROUPPHOTO"));
			gb.setmGroupAccessType(json.getString("GROUPACCESSTYPE"));
			tbList.add(gb);
		}
		setAdapter();
	} catch (Exception e) {
		// TODO: handle exception
		//Log.e("Errror", "error"+e.getMessage());
		e.printStackTrace();
	}
}
 
开发者ID:mityung,项目名称:XERUNG,代码行数:30,代码来源:SearchList.java

示例12: buildReportTableData

import org.json.JSONObject; //导入方法依赖的package包/类
@Override
public TableResponseModel buildReportTableData(String json, ReportViewType viewType,
                                               QueryRequestModel model) throws Exception {
  JSONObject jsonObject = new JSONObject(json);
  if (!jsonObject.has(HEADINGS)) {
    xLogger.warn("No data found");
    return null;
  }
  JSONArray headersJson = jsonObject.getJSONArray(HEADINGS);
  if (headersJson.length() < 3) {
    xLogger.warn("Insufficient data found. Expect to have at least 3 columns");
    return null;
  }
  jsonObject = constructTableBaseData(jsonObject, viewType, headersJson, model);
  if (jsonObject.has(TABLE) && jsonObject.getJSONObject(TABLE).length() != 0) {
    TableResponseModel response = new TableResponseModel();
    JSONArray jsonArray = jsonObject.getJSONArray(HEADINGS);
    JSONArray labelJsonArray = jsonObject.getJSONArray(LABEL_HEADINGS);
    for (int i = 0; i < labelJsonArray.length(); i++) {
      response.headings.add(labelJsonArray.getString(i));
    }

    List<Field> fields = new ArrayList<>(headersJson.length());
    for (int j = 0; j < headersJson.length(); j++) {
      fields.add(Report.class.getDeclaredField(headersJson.getString(j)));
    }
    JSONObject results = jsonObject.getJSONObject(TABLE);
    Map<String, List<List<ReportDataModel>>> tables = new HashMap<>(results.length());
    JSONArray dimensions = results.names();
    for (int i = 0; i < dimensions.length(); i++) {
      JSONArray period = results.getJSONArray(dimensions.getString(i));
      String key = getTableKeyByViewType(viewType, dimensions.getString(i));
      tables.put(key, new ArrayList<List<ReportDataModel>>(period.length()));
      List<Report> reports = new ArrayList<>();
      for (int j = 0; j < period.length(); j++) {
        JSONArray row = period.getJSONArray(j);
        Report r = constructReport(fields.subList(2, fields.size()), row);
        r.setTime(jsonArray.getString(j + 1));
        reports.add(r);
      }
      for (Report report : reports) {
        tables.get(key).add(getReportValues(report, ReportCompareField.NONE));
      }
    }
    response.table = tables;
    return response;
  }
  return null;
}
 
开发者ID:logistimo,项目名称:logistimo-web-service,代码行数:50,代码来源:AssetStatusReportService.java

示例13: getPostData

import org.json.JSONObject; //导入方法依赖的package包/类
JSONObject getPostData(Context context, ArrayList<AdUnit> adUnits) {
    if (context != null) {
        AdvertisingIDUtil.retrieveAndSetAAID(context);
        Settings.update(context);
    }
    JSONObject postData = new JSONObject();
    try {
        postData.put(Settings.REQUEST_SORT_BIDS, 1);
        postData.put(Settings.REQUEST_TID, generateTID());
        postData.put(Settings.REQUEST_ACCOUNT_ID, Prebid.getAccountId());
        postData.put(Settings.REQUEST_MAX_KEY, 20);
        if (Prebid.getAdServer() == Prebid.AdServer.DFP) {
            postData.put(Settings.REQUEST_CACHE_MARKUP, 0);
        } else {
            postData.put(Settings.REQUEST_CACHE_MARKUP, 1);
        }
        // add ad units
        JSONArray adUnitConfigs = getAdUnitConfigs(adUnits);
        if (adUnitConfigs != null && adUnitConfigs.length() > 0) {
            postData.put(Settings.REQUEST_AD_UNITS, adUnitConfigs);
        }
        // add device
        JSONObject device = getDeviceObject(context);
        if (device != null && device.length() > 0) {
            postData.put(Settings.REQUEST_DEVICE, device);
        }
        // add app
        JSONObject app = getAppObject(context);
        if (device != null && device.length() > 0) {
            postData.put(Settings.REQUEST_APP, app);
        }
        // todo the following are not in pbs_request.json, add request to support this?
        // add user
        // todo should we provide api for developers to pass in user's location (zip, city, address etc, not real time location)
        JSONObject user = getUserObject();
        if (user != null && user.length() > 0) {
            postData.put(Settings.REQUEST_USER, user);
        }
        // add custom keywords
        JSONArray keywords = getCustomKeywordsArray();
        if (keywords != null && keywords.length() > 0) {
            postData.put(Settings.REQUEST_KEYWORDS, keywords);
        }
        JSONObject version = getSDKVersion();
        if (version != null && version.length() > 0) {
            postData.put(Settings.REQUEST_SDK, version);
        }
    } catch (JSONException e) {
    }
    return postData;
}
 
开发者ID:prebid,项目名称:prebid-mobile-android,代码行数:52,代码来源:PrebidServerAdapter.java

示例14: getAll

import org.json.JSONObject; //导入方法依赖的package包/类
/**
 * Get all bug for all strategic point
 * @param listBug Strategic point 's list
 * @since 1.00
 */
public void getAll(ArrayList<Bug> listBug)
{	
	String url ="http://"+StrategicPoint.SERVER_NAME+":"+StrategicPoint.PORT_NUMBER+"/bugs";	
	
	GetData getSPs = new GetData();		
	JSONArray json = getSPs.Start(url);	
	int iBug = 0, iSolution=0, iSps;

	for(iSps=0;iSps<json.length();iSps++)
	{
		try 
		{	
			JSONObject jsonObject = json.getJSONObject(iSps);
	
			if(jsonObject.length()>0)
			{
				
									
				if(iSps>0)
				{
					if(jsonObject.getInt("id") == listBug.get(iBug-1).getID())
					{
						iBug--;		
						iSolution++;
						listBug.get(iBug).getListSolution().add(new Solution());
					}		
					else
					{
						iSolution=0;
						listBug.add(new Bug());	
						listBug.get(iBug).getListSolution().add(new Solution());
					}
				}
				else
				{
					
					listBug.add(new Bug());		
					listBug.get(iBug).getListSolution().add(new Solution());
			
				}
				
				
				listBug.get(iBug).setID( jsonObject.getInt("id"));
				listBug.get(iBug).setName(jsonObject.getString("name"));
				listBug.get(iBug).setThresholdValue(jsonObject.getInt("value"));
				listBug.get(iBug).setDetail(jsonObject.getString("errorDetail"));
				listBug.get(iBug).setCategory(jsonObject.getString("category"));
				listBug.get(iBug).setIDcolor((byte) jsonObject.getInt("IDColor"));	
				
				listBug.get(iBug).getListSolution().get(iSolution).setDescription(jsonObject.getString("solution"));

				iBug++;
			}								
		} 
		
		catch (JSONException e) 
		{				
			e.printStackTrace();
		}	
	}
	
	
}
 
开发者ID:Will30,项目名称:MonitorYourLAN,代码行数:69,代码来源:Bug.java

示例15: buildReportTableData

import org.json.JSONObject; //导入方法依赖的package包/类
@Override
public TableResponseModel buildReportTableData(String json, ReportViewType viewType,
                                               QueryRequestModel model) throws Exception {
  JSONObject jsonObject = new JSONObject(json);
  if (!jsonObject.has(HEADINGS)) {
    xLogger.warn("No data found");
    return null;
  }
  JSONArray headersJson = jsonObject.getJSONArray(HEADINGS);
  if (headersJson.length() < 3) {
    xLogger.warn("Insufficient data found. Expect to have at least 3 columns");
    return null;
  }
  jsonObject = constructTableBaseData(jsonObject, viewType, headersJson, model);
  if (jsonObject.has(TABLE) && jsonObject.getJSONObject(TABLE).length() != 0) {
    TableResponseModel response = new TableResponseModel();
    JSONArray jsonArray = jsonObject.getJSONArray(HEADINGS);
    JSONArray labelJsonArray = jsonObject.getJSONArray(LABEL_HEADINGS);
    for (int i = 0; i < labelJsonArray.length(); i++) {
      response.headings.add(labelJsonArray.getString(i));
    }

    List<Field> fields = new ArrayList<>(headersJson.length());
    for (int j = 0; j < headersJson.length(); j++) {
      fields.add(Report.class.getDeclaredField(headersJson.getString(j)));
    }
    JSONObject results = jsonObject.getJSONObject(TABLE);
    Map<String, List<List<ReportDataModel>>> tables = new HashMap<>(results.length());
    JSONArray dimensions = results.names();
    boolean isMatInvolved = (viewType == ReportViewType.BY_MATERIAL
        || model.filters.containsKey(QueryHelper.TOKEN + QueryHelper.QUERY_MATERIAL));
    boolean isKioskInvolved = (viewType == ReportViewType.BY_ENTITY
        || model.filters.containsKey(QueryHelper.TOKEN + QueryHelper.QUERY_ENTITY));
    for (int i = 0; i < dimensions.length(); i++) {
      JSONArray period = results.getJSONArray(dimensions.getString(i));
      String key = getTableKeyByViewType(viewType, dimensions.getString(i));
      tables.put(key, new ArrayList<List<ReportDataModel>>(period.length()));
      List<Report> reports = new ArrayList<>();
      for (int j = 0; j < period.length(); j++) {
        JSONArray row = period.getJSONArray(j);
        Report r = constructReport(fields.subList(2, fields.size()), row);
        r.setTime(jsonArray.getString(j + 1));
        reports.add(r);
      }
      for (Report report : reports) {
        tables.get(key).add(getReportValues(report, ReportCompareField.NONE,
            isMatInvolved, isKioskInvolved));
      }
    }
    response.table = tables;
    return response;
  }
  return null;
}
 
开发者ID:logistimo,项目名称:logistimo-web-service,代码行数:55,代码来源:AbnormalStockReportService.java


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