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


Java JSONObject.getString方法代码示例

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


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

示例1: responseResult

import net.sf.json.JSONObject; //导入方法依赖的package包/类
/** 
 * 返回服务端处理结果 
 * @param obj 服务端输出对象 
 * @return 输出处理结果给前段JSON格式数据 
 * @author YANGHONGXIA 
 * @since 2015-01-06 
 */  
public String responseResult(Object obj){  
    JSONObject jsonObj = null;  
    if(obj != null){  
        logger.info("后端返回对象:{}", obj);  
        JsonConfig jsonConfig = new JsonConfig();   
        jsonConfig.registerJsonValueProcessor(Date.class, new JsonDateValueProcessor());  
        jsonObj = JSONObject.fromObject(obj, jsonConfig);  
        logger.info("后端返回数据:" + jsonObj);  
        if(HttpConstants.SERVICE_RESPONSE_SUCCESS_CODE.equals(jsonObj.getString(HttpConstants.SERVICE_RESPONSE_RESULT_FLAG))){  
            jsonObj.element(HttpConstants.RESPONSE_RESULT_FLAG_ISERROR, false);  
            jsonObj.element(HttpConstants.SERVICE_RESPONSE_RESULT_MSG, "");  
        }else{  
            jsonObj.element(HttpConstants.RESPONSE_RESULT_FLAG_ISERROR, true);  
            String errMsg = jsonObj.getString(HttpConstants.SERVICE_RESPONSE_RESULT_MSG);  
            jsonObj.element(HttpConstants.SERVICE_RESPONSE_RESULT_MSG, errMsg==null?HttpConstants.SERVICE_RESPONSE_NULL:errMsg);  
        }  
    }  
    logger.info("输出结果:{}", jsonObj.toString());  
    return jsonObj.toString();  
}
 
开发者ID:lonelyshine,项目名称:xcx-specialty,代码行数:28,代码来源:BaseController.java

示例2: decodeJson

import net.sf.json.JSONObject; //导入方法依赖的package包/类
public static WsPacket decodeJson(String stringResult) {
	try {

		JSONObject jsObj = JSONObject.fromObject(stringResult);
		String wsOpCode = jsObj.getString(WSOPCODE);
		if (wsOpCode == null) {
			if (WSManager.log != null) {
				WSManager.log.warn("数据为:" + stringResult + ",无wsOpCode");
			}
			return null;
		}
		if (!WSManager.wsOpCodeMap.containsKey(wsOpCode)) {
			if (WSManager.log != null) {
				WSManager.log.warn("wsOpCode为:" + wsOpCode + "无对应解析,请及时解决");
			}
			return null;
		}
		Class<?> className = WSManager.wsOpCodeMap.get(wsOpCode);

		Method buildM = className.getDeclaredMethod("newBuilder");
		AbstractMessage.Builder<?> builder = (Builder<?>) buildM.invoke(null);
		Message data = PacketUtils.jsonToProtoBuf(stringResult, builder);
		WsPacket wsPacket = new WsPacket(wsOpCode, data);
		return wsPacket;
	} catch (Exception e) {
		if (WSManager.log != null) {
			WSManager.log.error("json转换成protobuf异常", e);
		}
		return null;
	}
}
 
开发者ID:dianbaer,项目名称:grain,代码行数:32,代码来源:WSCodeUtil.java

示例3: upload

import net.sf.json.JSONObject; //导入方法依赖的package包/类
@Override
public String upload(byte[] data, String path) {
    //腾讯云必需要以"/"开头
    if (!path.startsWith("/")) {
        path = "/" + path;
    }

    //上传到腾讯云
    UploadFileRequest request = new UploadFileRequest(config.getQcloudBucketName(), path, data);
    String response = client.uploadFile(request);

    JSONObject jsonObject = JSONObject.fromObject(response);
    if (jsonObject.getInt("code") != 0) {
        throw new RRException("文件上传失败," + jsonObject.getString("message"));
    }

    return config.getQcloudDomain() + path;
}
 
开发者ID:davichi11,项目名称:my-spring-boot-project,代码行数:19,代码来源:QcloudAbstractCloudStorageService.java

示例4: getOauth2Token

import net.sf.json.JSONObject; //导入方法依赖的package包/类
/**
 * 获取网页授权凭证
 * @param appId
 * @param appSecret
 * @param code
 * @return
 */
public Oauth2Token getOauth2Token(String appId,String appSecret,String code){
	Oauth2Token oauth2Token = null;
	String requestUrl = access_token_url.replace("APPID", appId).replace("SECRET", appSecret).replace("CODE", code);
	logger.info("getOauth2Token => ###### requestUrl : " + requestUrl);
	JSONObject jsonObject = CommonUtil.httpsRequest(requestUrl, "GET", null);
	if(null != jsonObject){
		try{
			oauth2Token = new Oauth2Token();
			oauth2Token.setAccessToken(jsonObject.getString("access_token"));
			oauth2Token.setExpiresIn(jsonObject.getInt("expires_in"));
			oauth2Token.setRefreshToken(jsonObject.getString("refresh_token"));
			oauth2Token.setOpenId(jsonObject.getString("openid"));
			oauth2Token.setScope(jsonObject.getString("scope"));
		}catch(Exception e){
			oauth2Token = null;
			int errCode = jsonObject.getInt("errcode");
			String errMsg = jsonObject.getString("errmsg");
			logger.error("获取网页授权凭证失败 errCode : {} , errmsg : {} ", errCode,errMsg);
		}
	}
	logger.info("getOauth2Token => 返回 :" + com.alibaba.fastjson.JSONObject.toJSONString(oauth2Token)); 
	return oauth2Token;
}
 
开发者ID:tojaoomy,项目名称:private-WeChat,代码行数:31,代码来源:AuthorizationService.java

示例5: hasFormDataKey

import net.sf.json.JSONObject; //导入方法依赖的package包/类
protected String hasFormDataKey(JSONObject formData, GlobalConfig globalConfig) {

        String instanceName;

        if (formData.containsKey("sonarInstancesName")) {
            instanceName = formData.getString("sonarInstancesName");
        } else {
            instanceName = globalConfig.fetchListOfGlobalConfigData().get(0).getName();
        }

        return instanceName;
    }
 
开发者ID:jenkinsci,项目名称:sonar-quality-gates-plugin,代码行数:13,代码来源:JobConfigurationService.java

示例6: getDocumentDescription

import net.sf.json.JSONObject; //导入方法依赖的package包/类
@Override
public String getDocumentDescription(ExternalDocumentServiceContext context, JSONObject doc, Locale preferredLocale) {
    if (doc != null && doc.has("description")) {
        return doc.getString("description");
    }

    return "";
}
 
开发者ID:jenskooij,项目名称:hippo-external-document-picker-example-implementation,代码行数:9,代码来源:DocumentServiceFacade.java

示例7: configure

import net.sf.json.JSONObject; //导入方法依赖的package包/类
@Override
public boolean configure(StaplerRequest req, JSONObject formData) throws FormException {
    // To persist global configuration information,
    // set that to properties and call save().
    useDefault = formData.getBoolean("useDefault");
    exePath = formData.getString("exePath");
    // ^Can also use req.bindJSON(this, formData);
    //  (easier when there are many fields; need set* methods for this, like setUseDefault)
    save();
    return super.configure(req, formData);
}
 
开发者ID:TommyLin,项目名称:cppchecker,代码行数:12,代码来源:Cppchecker.java

示例8: startAnonymousExternal

import net.sf.json.JSONObject; //导入方法依赖的package包/类
/**
 * Start Anonymous External test
 * @return public link to the report
 */
public String startAnonymousExternal() throws IOException {
    JSONObject result = sendStartTest(httpUtils.getAddress() + "/api/v4/sessions", 201);
    setTestFields(result.getJSONObject("test"));
    reportURL = result.getString("publicTokenUrl");
    fillFields(result);
    return reportURL;
}
 
开发者ID:Blazemeter,项目名称:jmeter-bzm-plugins,代码行数:12,代码来源:Test.java

示例9: findMosaicFeeInformationByNIS

import net.sf.json.JSONObject; //导入方法依赖的package包/类
public static MosaicFeeInformation findMosaicFeeInformationByNIS(MosaicId mosaicId){
	String queryResult = HttpClientUtils.get(Constants.URL_NAMESPACE_MOSAIC_DEFINITION_PAGE + "?namespace=" + mosaicId.getNamespaceId().toString());
	JSONObject json = JSONObject.fromObject(queryResult);
	if(json==null || !json.containsKey("data") || json.getJSONArray("data").size()==0){
		return null;
	}
	JSONArray array = json.getJSONArray("data");
	for(int i=0;i<array.size();i++){
		JSONObject item = array.getJSONObject(i);
		JSONObject mosaic = item.getJSONObject("mosaic");
		JSONObject id = mosaic.getJSONObject("id");
		if(mosaicId.getName().equals(id.getString("name"))){
			JSONArray properties = mosaic.getJSONArray("properties");
			String initialSupply = "";
			String divisibility = "";
			for(int j=0;j<properties.size();j++){
				JSONObject property = properties.getJSONObject(j);
				if("initialSupply".equals(property.getString("name"))){
					initialSupply = property.getString("value");
				} else if("divisibility".equals(property.getString("name"))){
					divisibility = property.getString("value");
				}
			}
			if(!"".equals(initialSupply) && !"".equals(divisibility)){
				return new MosaicFeeInformation(Supply.fromValue(Long.valueOf(initialSupply)), Integer.valueOf(divisibility));
			}
		}
	}
	return null;
}
 
开发者ID:NEMChina,项目名称:nem-apps,代码行数:31,代码来源:NISQuery.java

示例10: newInstance

import net.sf.json.JSONObject; //导入方法依赖的package包/类
@Override public Step newInstance(StaplerRequest req, JSONObject formData) throws FormException {
    String overridesS = formData.getString("overrides");
    List<String> overrides = new ArrayList<>();
    for (String line : overridesS.split("\r?\n")) {
        line = line.trim();
        if (!line.isEmpty()) {
            overrides.add(line);
        }
    }
    return new EnvStep(overrides);
}
 
开发者ID:10000TB,项目名称:Jenkins-Plugin-Examples,代码行数:12,代码来源:EnvStep.java

示例11: configure

import net.sf.json.JSONObject; //导入方法依赖的package包/类
@Override
public synchronized boolean configure(StaplerRequest req, JSONObject formData) throws FormException {
   wait = formData.getString("wait");
   waitUnit = ITimedMicrocksPlugin.TimeoutUnit.normalize(formData.getString("waitUnit"));
   if (wait == null || wait.isEmpty()) {
      // If someone clears the value, go back to default and use seconds
      wait = "" + getStaticDefaultWaitTime() / ITimedMicrocksPlugin.TimeoutUnit.SECONDS.multiplier;
      waitUnit = ITimedMicrocksPlugin.TimeoutUnit.SECONDS.name;
   }
   wait = wait.trim();
   save();
   return true;
}
 
开发者ID:microcks,项目名称:microcks-jenkins-plugin,代码行数:14,代码来源:TimedBuildStepDescriptor.java

示例12: findMosaicFeeInformationByNIS

import net.sf.json.JSONObject; //导入方法依赖的package包/类
public static MosaicFeeInformation findMosaicFeeInformationByNIS(String host, String port, MosaicId mosaicId){
	
	NemNetworkResponse queryResult = NetworkUtils.get("http://"+host+":"+port+NemAppsLibGlobals.URL_NAMESPACE_MOSAIC_DEFINITION_PAGE + "?namespace=" + mosaicId.getNamespaceId().toString());
	
	
	JSONObject json = JSONObject.fromObject(queryResult.getResponse());
	if(json==null || !json.containsKey("data") || json.getJSONArray("data").size()==0){
		return null;
	}
	JSONArray array = json.getJSONArray("data");
	for(int i=0;i<array.size();i++){
		JSONObject item = array.getJSONObject(i);
		JSONObject mosaic = item.getJSONObject("mosaic");
		JSONObject id = mosaic.getJSONObject("id");
		if(mosaicId.getName().equals(id.getString("name"))){
			JSONArray properties = mosaic.getJSONArray("properties");
			String initialSupply = "";
			String divisibility = "";
			for(int j=0;j<properties.size();j++){
				JSONObject property = properties.getJSONObject(j);
				if("initialSupply".equals(property.getString("name"))){
					initialSupply = property.getString("value");
				} else if("divisibility".equals(property.getString("name"))){
					divisibility = property.getString("value");
				}
			}
			if(!"".equals(initialSupply) && !"".equals(divisibility)){
				return new MosaicFeeInformation(Supply.fromValue(Long.valueOf(initialSupply)), Integer.valueOf(divisibility));
			}
		}
	}
	return null;
}
 
开发者ID:NEMPH,项目名称:nem-apps-lib,代码行数:34,代码来源:NISQuery.java

示例13: getUserInfo

import net.sf.json.JSONObject; //导入方法依赖的package包/类
@SuppressWarnings({ "deprecation", "unchecked" })
	public SNSUserInfo getUserInfo(String accessToken,String openId){
		logger.info("getUserInfo accessToken : {} , openId : {} ", accessToken, openId);
		SNSUserInfo user = null;
		String requestUrl = userinfo_url.replace("OPENID", openId).replace("ACCESS_TOKEN", accessToken);
		JSONObject jsonObject = CommonUtil.httpsRequest(requestUrl, "GET", null);
		if(null != jsonObject){
//			logger.info("授权返回JSONObject 数据 : " + com.meidusa.fastjson.JSONObject.toJSONString(jsonObject));
			logger.info("授权返回JSONObject 数据 : Key : {}, values : {} " ,com.alibaba.fastjson.JSONObject.toJSONString(jsonObject.keySet()), 
					com.alibaba.fastjson.JSONObject.toJSONString(jsonObject.values()));
			try{
				user = new SNSUserInfo();
				user.setOpenId(jsonObject.getString("openid"));
				user.setNickname(jsonObject.getString("nickname"));
				user.setSex(jsonObject.getInt("sex"));
				user.setProvince(jsonObject.getString("province"));
				user.setCity(jsonObject.getString("city"));
				user.setCountry(jsonObject.getString("country"));
				user.setHeadimgurl(jsonObject.getString("headimgurl"));
				user.setPrivilegeList(JSONArray.toList(jsonObject.getJSONArray("privilege"), List.class));
			}catch(Exception e){
				logger.error("网页授权获取用户信息失败 " + e.getMessage());
				user = null;
				int errCode = jsonObject.getInt("errcode");
				String errMsg = jsonObject.getString("errmsg");
				logger.error("网页授权获取用户信息失败 errCode : {} , errmsg : {} ", errCode,errMsg);
			}
		}
		logger.info("getUserInfo => 返回  : " + com.alibaba.fastjson.JSONObject.toJSONString(user));
		return user;		
	}
 
开发者ID:tojaoomy,项目名称:private-WeChat,代码行数:32,代码来源:AuthorizationService.java

示例14: updateRoomTypeInfo

import net.sf.json.JSONObject; //导入方法依赖的package包/类
@Action(value="updateRoomTypeInfo")
public void updateRoomTypeInfo() throws Exception{
String roomJson=(String) request.getParameter("json").trim();
	
	JSONObject jsonObject = JSONObject.fromObject(roomJson);
	String typeId = jsonObject.getString("rcName");
	String typeName = jsonObject.getString("rcBedNumber");
	String priceString = jsonObject.getString("rcPrePrice");
	String discountString = jsonObject.getString("rcPreDiscount");
	
	priceString=priceString.trim();
	discountString=discountString.trim();
	
	Float price=Float.parseFloat(priceString);
	Float discount=Float.parseFloat(discountString);
	
	Roomtype roomtype = roomtypeService.findRoomtypeByTypeId(1, typeId);
	Hotel hotel = hotelService.getById(1);
	System.out.println();
	if(roomtype==null){
		roomtype = new Roomtype();
		roomtype.setTypeName(typeName);
		roomtype.setTypeId(typeId);
		roomtype.setPrice(price);
		roomtype.setDiscount(discount);
		roomtype.setHotel(hotel);
		roomtypeService.save(roomtype);
	}
	else{
		roomtype.setTypeName(typeName);
		roomtype.setTypeId(typeId);
		roomtype.setPrice(price);
		roomtype.setDiscount(discount);
		roomtype.setHotel(hotel);
		roomtypeService.update(roomtype);
	}
	response.getWriter().write("{success:true}");
	return;
}
 
开发者ID:liuxuanhai,项目名称:WeiXing_xmu-2016-MrCode,代码行数:40,代码来源:RoomAction.java

示例15: getCredential

import net.sf.json.JSONObject; //导入方法依赖的package包/类
public static Credential getCredential(String url,HttpHeader cookies){
	HttpUtils util=new HttpUtils();
	//必须设置不跟随重定向,否则无法取得cookies
	util.setGetFollowRedirect(false);
	//访问302跳转的url
	Response response=util.get(url);
	StringBuffer cookie=new StringBuffer();
	//取出cookies
	ArrayList<HttpHeader> headers=response.getHeaders();
	String[] cookieArray=cookies.getValue().split(" ");
	String ptwebqq=null;
	for(int i=0;i<cookieArray.length;i++){
		//获取ptwebqq
		if(cookieArray[i].contains("ptwebqq")){
			ptwebqq=cookieArray[i].substring(cookieArray[i].indexOf("=")+1,cookieArray[i].indexOf(";"));
			break;
		}
	}
	//在cookies内添加ptwebqq项
	cookie.append("ptwebqq="+ptwebqq+"; ");
	for(int i=0;i<headers.size();i++){
		if(headers.get(i).getHeader()==null){
			continue;
		}
		if(headers.get(i).getHeader().equals("Set-Cookie")){
		String temp=headers.get(i).getValue().substring(0,headers.get(i).getValue().indexOf(";")+1);
		//判断每一项cookie的值是否为空,如果等于号后面直接就是分号结尾,那就是空值,需要过滤
		if(!temp.substring(temp.indexOf("=")+1,temp.length()).equals(";")){
		cookie.append(temp+" ");
		}
		}
	}
	//生成一个登录表单
	JSONObject r=new JSONObject();
	r.put("ptwebqq",ptwebqq);
	r.put("clientid",53999199);
	r.put("psessionid","");
	r.put("status","online");
	//访问登录链接,需要带上前面的cookies访问
	Response loginResult=util.post(URL.URL_LOGIN,new PostParameter[]{new PostParameter("r",r.toString())},new HttpHeader[]{new HttpHeader("Cookie",cookie.toString())});
	JSONObject result=JSONObject.fromObject(JSONObject.fromObject(loginResult.getContent("UTF-8")));
	JSONObject data=JSONObject.fromObject(result.get("result"));
	//获取自己的uin
	long uin=data.getLong("uin");
	//获取psessionid,这个在收发消息需要用到
	String psessionid=data.getString("psessionid");
	//获取vfwebqq,必须带上Referer和前面的cookies
	String vfwebqq_temp=util.get(URL.URL_GET_VFWEBQQ,new HttpHeader[]{URL.URL_REFERER,new HttpHeader("Cookie",cookie.toString())}).getContent("UTF-8");
	//将结果解析为JSON对象
	JSONObject result_jsonObj=JSONObject.fromObject(vfwebqq_temp);
	//构造一个凭据对象,将获取到的数据全部传入
	Credential credential=new Credential(uin,result_jsonObj.getJSONObject("result").getString("vfwebqq"),psessionid,ptwebqq,new HttpHeader("Cookie",cookie.toString()));
	//返回码,这个可有可无,无所谓
	credential.setRetcode(result.getInt("retcode"));
	return credential;
}
 
开发者ID:KittenDev,项目名称:WebQQAPI,代码行数:57,代码来源:QrcodeLogin.java


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