本文整理匯總了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();
}
示例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;
}
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}