當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。