本文整理汇总了Java中com.alibaba.fastjson.JSONObject.getString方法的典型用法代码示例。如果您正苦于以下问题:Java JSONObject.getString方法的具体用法?Java JSONObject.getString怎么用?Java JSONObject.getString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.alibaba.fastjson.JSONObject
的用法示例。
在下文中一共展示了JSONObject.getString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import com.alibaba.fastjson.JSONObject; //导入方法依赖的package包/类
@Test
public void main() throws IOException {
File a = FileUtils.getFile("D:/a.txt");
String str = FileUtils.readFileToString(a,"utf-8");
JSONObject json = JSON.parseObject(str);
JSONArray arry = JSONArray.parseArray(json.get("delegates").toString());
for(int i = 0;i<arry.size();i++){
JSONObject obj= (JSONObject) arry.get(i);
String username = obj.getString("username");
String productivity = obj.getString("productivity");
String producedblocks = obj.getString("producedblocks");
String balance = obj.getString("balance");
String approval = obj.getString("approval");
System.out.println(username +"||" + productivity +"||" + producedblocks + "||" + balance + "||" + approval);
}
}
示例2: getWxUserinfo
import com.alibaba.fastjson.JSONObject; //导入方法依赖的package包/类
/** 获取微信用户信息 */
public static final ThirdPartyUser getWxUserinfo(String token, String openid) throws Exception {
ThirdPartyUser user = new ThirdPartyUser();
String url = Resources.THIRDPARTY.getString("getUserInfoURL_wx");
url = url + "?access_token=" + token + "&openid=" + openid;
String res = HttpUtil.httpClientPost(url);
JSONObject json = JSONObject.parseObject(res);
if (json.getString("errcode") == null) {
user.setUserName(json.getString("nickname"));
String img = json.getString("headimgurl");
if (img != null && !"".equals(img)) {
user.setAvatarUrl(img);
}
String sex = json.getString("sex");
if ("0".equals(sex)) {
user.setGender("0");
} else {
user.setGender("1");
}
} else {
throw new IllegalArgumentException(json.getString("errmsg"));
}
return user;
}
示例3: convert
import com.alibaba.fastjson.JSONObject; //导入方法依赖的package包/类
@Override
public ArrayList<MultipleItemEntity> convert() {
final ArrayList<MultipleItemEntity> dataList = new ArrayList<>();
final JSONArray dataArray = JSON.parseObject(getJsonData())
.getJSONObject("data").getJSONArray("list");
final int size = dataArray.size();
for (int i = 0; i < size; i++) {
final JSONObject data = dataArray.getJSONObject(i);
final int id = data.getInteger("id");
final String name = data.getString("name");
final MultipleItemEntity entity = MultipleItemEntity.builder()
.setField(MultipleFields.ITEM_TYPE, ItemType.VERTICAL_MENU_LIST)
.setField(MultipleFields.ID, id)
.setField(MultipleFields.TEXT, name)
.setField(MultipleFields.TAG, false).build();
dataList.add(entity);
//设置选中第一个
dataList.get(0).setField(MultipleFields.TAG, true);
}
return dataList;
}
示例4: getMasterID
import com.alibaba.fastjson.JSONObject; //导入方法依赖的package包/类
/**
* 获得master结点 server id
*
* @param workerType
* @return
*/
public static String getMasterID(ZkClient zkClient,String workerType){
String zkPath = "/"+ Constants.SAF_WORKER_ROOT+"/"+workerType+"/"+Constants.SAF_WORKER_SERVER;
byte[] value = zkClient.readData(zkPath,true);
if( value == null || value[0] == 0){
logger.warn("{} master is null", zkPath);
return null;
}
String master = new String(value);
if ( StringUtils.isEmpty(master)){
logger.warn("{} master is null", zkPath);
return null;
}
JSONObject masterJSON = null;
try {
masterJSON = JSONObject.parseObject(master);
} catch (JSONException e) {
logger.error("#{}# error master server id for [{}} ",master,workerType,e);
return null;
}
return StringUtils.isNotEmpty(masterJSON.getString(FIXEDMASTER)) ? masterJSON.getString(FIXEDMASTER):masterJSON.getString(MASTERID);
}
示例5: parseReceive
import com.alibaba.fastjson.JSONObject; //导入方法依赖的package包/类
protected DataTransferObject parseReceive(String jsonResult) {
DataTransferObject dto = new DataTransferObject();
//判断为空
if (Check.NuNStr(jsonResult)) {
dto.setErrCode(DataTransferObject.ERROR);
dto.putValue("data", "未取得返回数据");
return dto;
}
//转成map
JSONObject jsonObject = JSON.parseObject(jsonResult);
String code = jsonObject.getString("response_code");
//如果服务器返回异常
if (!"0".equals(code)) {
dto.setErrCode(DataTransferObject.ERROR);
dto.putValue("data", jsonObject.get("error_info"));
return dto;
}
//返回正确,将数据取回到dto
String uplinks = jsonObject.getString("uplinks");
List<SmsReceiveMessage> receiveMessages = JSON.parseArray(uplinks, SmsReceiveMessage.class);
dto.putValue("data", receiveMessages);
return dto;
}
示例6: doProcess
import com.alibaba.fastjson.JSONObject; //导入方法依赖的package包/类
@Override
public final QCloudMsgResponse doProcess(String jsonBody,Map<String,Object> urlParams,String key) {
JSONObject jsonObject = JSON.parseObject(jsonBody);
String sign = jsonObject.getString("sign");
long t = jsonObject.getLongValue("t");
if (!isValid(t, key, sign)) {
return onInvalidMsg(jsonBody);
}
int eventType = jsonObject.getIntValue("event_type");
switch (eventType) {
case LiveMsgEventType.CUT_STREAM:
return onCutStream(JSON.parseObject(jsonBody, LiveMsgStreamEventDO.class));
case LiveMsgEventType.PUSH_STREAM:
return onPushStream(JSON.parseObject(jsonBody, LiveMsgStreamEventDO.class));
case LiveMsgEventType.RECORD_AV_CREATED:
return onAvRecordCreated(JSON.parseObject(jsonBody, LiveMsgAvRecordCreatedDO.class));
case LiveMsgEventType.SCREENSHOT_CREATED:
return onScreenshotCreated(JSON.parseObject(jsonBody, LiveMsgScreenshotCreatedDO.class));
default:
break;
}
return LiveMsgResponse.FAILED;
}
示例7: createOrUpdateViewMeta
import com.alibaba.fastjson.JSONObject; //导入方法依赖的package包/类
/**
* update the meta if the view updated
*/
private void createOrUpdateViewMeta(ChildData childData, boolean isReplace) throws Exception {
String path = childData.getPath();
String[] paths = path.split("/");
String jsonValue = new String(childData.getData(), StandardCharsets.UTF_8);
JSONObject obj = (JSONObject) JSONObject.parse(jsonValue);
//if the view is create or replace by this server it self
String serverId = obj.getString(SERVER_ID);
if (serverId.equals(ZkConfig.getInstance().getValue(ZkParamCfg.ZK_CFG_MYID))) {
return;
}
String createSql = obj.getString(CREATE_SQL);
String schema = paths[paths.length - 1].split(SCHEMA_VIEW_SPLIT)[0];
ViewMeta vm = new ViewMeta(createSql, schema, DbleServer.getInstance().getTmManager());
vm.initAndSet(isReplace);
}
示例8: sinaCallback
import com.alibaba.fastjson.JSONObject; //导入方法依赖的package包/类
@RequestMapping("callback/sina")
public String sinaCallback(HttpServletRequest request, ModelMap modelMap) {
String host = request.getHeader("host");
try {
String code = request.getParameter("code");
if (StringUtils.isNotBlank(code)) {// 如果不为空
// 获取token和uid
JSONObject json = ThirdPartyLoginHelper.getSinaTokenAndUid(code, host);
String uid = json.getString("uid");
if (StringUtils.isNotBlank(uid)) {// 如果uid存在
// 获取第三方用户信息存放到session中
ThirdPartyUser thirdUser = ThirdPartyLoginHelper.getSinaUserinfo(json.getString("access_token"),
uid);
thirdUser.setProvider("SINA");
thirdPartyLogin(request, thirdUser);
// 跳转到登录成功界面
modelMap.put("retUrl", Resources.THIRDPARTY.getString("third_login_success"));
} else {// 如果未获取到OpenID
// 跳转到登录成功界面
modelMap.put("retUrl", "-1");
}
} else {// 如果没有返回令牌,则直接返回到登录页面
// 跳转到登录成功界面
modelMap.put("retUrl", "-1");
}
} catch (Exception e) {
// 跳转到登录失败界面
modelMap.put("retUrl", "-1");
e.printStackTrace();
}
return "/sns/redirect";
}
示例9: parse
import com.alibaba.fastjson.JSONObject; //导入方法依赖的package包/类
/**
* 从JsonObject中解析出SlaveNode
* @param object
* @return
*/
public static SlaveNode parse(JSONObject object){
if(object==null){
return null;
}
String host = object.getString("host");
int port = object.getIntValue("port");
String id = object.getString("id");
return new SlaveNode(id,host,port);
}
示例10: initToken
import com.alibaba.fastjson.JSONObject; //导入方法依赖的package包/类
private static void initToken() {
if (tokenTime == null || tokenExpire == null || System.currentTimeMillis() - tokenTime >= tokenExpire) {
String uriString = "https://api.weixin.qq.com/cgi-bin/token?grant_type=" + grantType + "&appid="
+ PropertiesUtil.getString("WX_PUBLIC_APPID") + "&secret="
+ PropertiesUtil.getString("WX_PUBLIC_SECRET");
try {
URL url = new URL(uriString);
HttpsURLConnection httpsURLConnection = (HttpsURLConnection) url.openConnection();
InputStreamReader inputStreamReader = new InputStreamReader(httpsURLConnection.getInputStream());
int responseInt = inputStreamReader.read();
StringBuffer stringBuffer = new StringBuffer();
while (responseInt != -1) {
stringBuffer.append((char) responseInt);
responseInt = inputStreamReader.read();
}
String tokenString = stringBuffer.toString();
JSONObject jsonObject = JSON.parseObject(tokenString);
if (jsonObject.containsKey("access_token")) {
tokenTime = System.currentTimeMillis();
token = jsonObject.getString("access_token");
tokenExpire = jsonObject.getLong("expires_in");
} else {
// TODO 验证错误
System.out.println(jsonObject.get("errcode"));
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
示例11: buildDottedNameSpace
import com.alibaba.fastjson.JSONObject; //导入方法依赖的package包/类
public String buildDottedNameSpace(String dataSourceInfo){
String dbName = (String)(this.properties.get(DBConfiguration.DataSourceInfo.DB_NAME));
JSONObject ds=JSONObject.parseObject(dataSourceInfo);
JSONObject payload = ds.getJSONObject(DataPullConstants.FullPullInterfaceJson.PAYLOAD_KEY);
// String dbSchema = (String)(this.properties.get(DBConfiguration.DataSourceInfo.DB_SCHEMA));
// String tableName = (String)(this.properties.get(DBConfiguration.DataSourceInfo.TABLE_NAME));
String dbSchema = payload.getString(DataPullConstants.FULL_DATA_PULL_REQ_PAYLOAD_SCHEMA_NAME);
String tableName = payload.getString(DataPullConstants.FULL_DATA_PULL_REQ_PAYLOAD_TABLE_NAME);
String version = payload.getString(DataPullConstants.FullPullInterfaceJson.VERSION_KEY);
return String.format("%s.%s.%s.%s", dbName, dbSchema, tableName, version);
}
示例12: parseUploadResult
import com.alibaba.fastjson.JSONObject; //导入方法依赖的package包/类
private void parseUploadResult(String result) {
JSONObject jsonObject = JSONObject.parseObject(result);
if (jsonObject.containsKey(PARAM_MEDIA_ID)) {
this.mediaId = jsonObject.getString(PARAM_MEDIA_ID);
this.createdTimestamp = jsonObject.getString(PARAM_CREATE_TIME);
} else {
this.mediaId = null;
this.createdTimestamp = null;
}
}
示例13: initToken
import com.alibaba.fastjson.JSONObject; //导入方法依赖的package包/类
private static void initToken() {
if (tokenTime == null || tokenExpire == null || System.currentTimeMillis() - tokenTime >= tokenExpire
|| token == null) {
String uriString = "https://qyapi.weixin.qq.com/cgi-bin/gettoken";
StringBuffer sb = new StringBuffer();
sb.append(uriString);
sb.append("?corpid=").append(PropertiesUtil.getString("WX_QY_CORPID"));
sb.append("&corpsecret=").append(PropertiesUtil.getString("WX_QY_CORPSECRET"));
try {
System.out.println(sb);
URL url = new URL(sb.toString());
HttpsURLConnection httpsURLConnection = (HttpsURLConnection) url.openConnection();
InputStreamReader inputStreamReader = new InputStreamReader(httpsURLConnection.getInputStream());
int responseInt = inputStreamReader.read();
StringBuffer stringBuffer = new StringBuffer();
while (responseInt != -1) {
stringBuffer.append((char) responseInt);
responseInt = inputStreamReader.read();
}
String tokenString = stringBuffer.toString();
System.out.println(stringBuffer);
JSONObject jsonObject = JSON.parseObject(tokenString);
if (jsonObject.containsKey("access_token")) {
tokenTime = System.currentTimeMillis();
token = jsonObject.getString("access_token");
tokenExpire = jsonObject.getLong("expires_in");
} else {
// TODO 验证错误
System.out.println(jsonObject.get("errcode"));
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
示例14: AccessToken
import com.alibaba.fastjson.JSONObject; //导入方法依赖的package包/类
public AccessToken(String res) throws WeiboException{
super();
JSONObject json =JSONObject.parseObject(res);
accessToken = json.getString("access_token");
expireIn = json.getString("expires_in");
refreshToken = json.getString("refresh_token");
uid = json.getString("uid");
}
示例15: push
import com.alibaba.fastjson.JSONObject; //导入方法依赖的package包/类
@JSMethod(uiThread = true)
public void push(String param, JSCallback callback) {
if (!TextUtils.isEmpty(param)) {
if (WXSDKEngine.getActivityNavBarSetter() != null) {
if (WXSDKEngine.getActivityNavBarSetter().push(param)) {
callback.invoke(MSG_SUCCESS);
return;
}
}
try {
JSONObject jsonObject = JSON.parseObject(param);
String url = jsonObject.getString(URL);
if (!TextUtils.isEmpty(url)) {
Uri rawUri = Uri.parse(url);
String scheme = rawUri.getScheme();
Uri.Builder builder = rawUri.buildUpon();
if (TextUtils.isEmpty(scheme)) {
builder.scheme(Constants.Scheme.HTTP);
}
Intent intent = new Intent(Intent.ACTION_VIEW, builder.build());
intent.addCategory(WEEX);
intent.putExtra(INSTANCE_ID, mWXSDKInstance.getInstanceId());
mWXSDKInstance.getContext().startActivity(intent);
callback.invoke(MSG_SUCCESS);
}
} catch (Exception e) {
WXLogUtils.eTag(TAG, e);
callback.invoke(MSG_FAILED);
}
}
callback.invoke(MSG_FAILED);
}