本文整理匯總了Java中com.alibaba.fastjson.JSONObject.getJSONObject方法的典型用法代碼示例。如果您正苦於以下問題:Java JSONObject.getJSONObject方法的具體用法?Java JSONObject.getJSONObject怎麽用?Java JSONObject.getJSONObject使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.alibaba.fastjson.JSONObject
的用法示例。
在下文中一共展示了JSONObject.getJSONObject方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: onHttpResponse
import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
@Override
public void onHttpResponse(int requestCode, String resultJson, Exception e) {
User user = null;
try {//如果服務器返回的json一定在最外層有個data,可以用OnHttpResponseListenerImpl解析
JSONObject jsonObject = JSON.parseObject(resultJson);
JSONObject data = jsonObject == null ? null : jsonObject.getJSONObject("data");
user = JSON.parseObject(data, User.class);
} catch (Exception e1) {
Log.e(TAG, "onHttpResponse try { user = Json.parseObject(... >>" +
" } catch (JSONException e1) {\n" + e1.getMessage());
}
if (BaseModel.isCorrect(user) == false && e != null) {
showShortToast(R.string.get_failed);
} else {
setUser(user);
}
}
示例2: register
import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
/**
* 注冊
*
* @param serverId 服務ID
* @param port 服務端口號
*/
public void register(String serverId, String port) {
this.sessionId = getRandomString();
this.serverId = serverId;
this.port = port;
// 發送注冊請求
try {
String resp = HttpUtils.sendGet(String.format("http://%s/register?id=%s&sessionId=%s&port=%s",
this.host, serverId, this.sessionId, port));
this.status = true;
JSONObject obj = JSON.parseObject(resp);
if (obj.getInteger(Constant.CODE) != 0) {
throw new ExceptionInInitializerError("register server fail");
}
JSONObject data = obj.getJSONObject(Constant.DATA);
String[] tmp = data.getString("PublicKey").split("\n");
this.publicKey = tmp[1] + tmp[2] + tmp[3] + tmp[4];
this.length = data.getInteger("Length");
this.timeout = data.getInteger("Timeout");
} catch (IOException ignored) {
}
}
示例3: exports
import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
public void exports(JSONObject font, Double splitAtX, Double splitAtY, Double err) {
font.put("CFF_", null);
JSONObject glyf = font.getJSONObject("glyf");
for (String k : glyf.keySet()) {
JSONObject g = glyf.getJSONObject(k);
Contour[][] contours = g.getObject("contours", Contour[][].class);
if (contours != null) {
contours = c2qContours(contours, splitAtX, splitAtY, err);
}
g.put("contours", contours);
g.put("stemH", null);
g.put("stemV", null);
g.put("hintMasks", null);
g.put("contourMasks", null);
}
JSONObject maxp = font.getJSONObject("maxp");
maxp.put("version", 1.0);
}
示例4: invoke
import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
@Override
public void invoke(Tuple4<String, Integer, String, Integer> inTuple4) throws InterruptedException {
try {
if (inTuple4 != null) {
if (inTuple4.f2 != null && !"".equals(inTuple4.f2.trim())) {
JSONObject data = JSONObject.parseObject(inTuple4.f2);
JSONObject filter = data.getJSONObject("filter");
JSONObject doc = data.getJSONObject("data");
if (data.getString("dbName") != null) {
mongoManager.executeUpsert(data.getString("dbName"), data.getString("collectionName"), filter, doc);
}
}
}
} catch (Exception e) {
logger.error("Mongo入庫發生捕獲的異常!{}:{}", e.getClass(), e.getMessage());
for (StackTraceElement element : e.getStackTrace()) {
logger.error("\tat {}", element.toString());
}
}
}
示例5: globalControlEmailJsonVo2HTML
import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
public static String globalControlEmailJsonVo2HTML(JSONObject json) {
JSONObject payload = json.getJSONObject("payload");
JSONObject beforeMap = payload.getJSONObject("before");
JSONObject afterMap = payload.getJSONObject("after");
final String HTML_LINE_SEPARATOR = "<br/>";
// final String HTML_INDENT = " ";
StringBuilder output = new StringBuilder();
output.append("您好,數據庫表結構發生變更!!!"+HTML_LINE_SEPARATOR);
output.append("時間:" + json.getString("timestamp") + HTML_LINE_SEPARATOR);
output.append("表名:" + StringUtils.join(new Object[] {payload.get("datasource"),payload.get("schema"),payload.get("table")}, ".") + HTML_LINE_SEPARATOR);
output.append("新版本號:" + payload.getString("version") + HTML_LINE_SEPARATOR);
output.append("變更前後對比:" + HTML_LINE_SEPARATOR);
output.append(compareListHTML(beforeMap.getJSONArray("columns"),afterMap.getJSONArray("columns")));
return output.toString();
}
示例6: parseEsResponse
import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
/**
* 解析log
* @param response
* @return
*/
private Map<String, Object> parseEsResponse(String response) {
Map<String, Object> result = new HashMap<String, Object>();
if (null == response) {
// 錯誤
return null;
} else {
JSONObject json = JSON.parseObject(response);
List<NoneDupeLogDto> logs = new ArrayList<NoneDupeLogDto>();
JSONObject hits = json.getJSONObject("hits");
Iterator<Object> iterator = hits.getJSONArray("hits").iterator();
while (iterator.hasNext()) {
LogDto logDto = JSON.parseObject(((JSONObject) iterator.next()).getString("_source"), LogDto.class);
logs.add(new NoneDupeLogDto(logDto.getNanoTime(), logDto.toString()));
}
result.put("logs", logs);
result.put("total", hits.getInteger("total"));
result.put("current", logs.size());
return result;
}
}
示例7: sendAckInfoToCtrlTopic
import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
private static void sendAckInfoToCtrlTopic(String dataSourceInfo, String completedTime, String pullStatus) {
try {
// 在源dataSourceInfo的基礎上,更新全量拉取相關信息。然後發回src topic
JSONObject jsonObj = JSONObject.parseObject(dataSourceInfo);
jsonObj.put(DataPullConstants.FullPullInterfaceJson.FROM_KEY, DataPullConstants.FullPullInterfaceJson.FROM_VALUE);
jsonObj.put(DataPullConstants.FullPullInterfaceJson.TYPE_KEY, DataPullConstants.FullPullInterfaceJson.TYPE_VALUE);
// notifyFullPullRequestor
JSONObject payloadObj = jsonObj.getJSONObject(DataPullConstants.FullPullInterfaceJson.PAYLOAD_KEY);
// 完成時間
payloadObj.put(DataPullConstants.FullPullInterfaceJson.COMPLETE_TIME_KEY, completedTime);
// 拉取是否成功標誌位
payloadObj.put(DataPullConstants.FullPullInterfaceJson.DATA_STATUS_KEY, pullStatus);
jsonObj.put(DataPullConstants.FullPullInterfaceJson.PAYLOAD_KEY, payloadObj);
String ctrlTopic = getFullPullProperties(Constants.ZkTopoConfForFullPull.COMMON_CONFIG, true)
.getProperty(Constants.ZkTopoConfForFullPull.FULL_PULL_SRC_TOPIC);
Producer producer = DbusHelper
.getProducer(getFullPullProperties(Constants.ZkTopoConfForFullPull.BYTE_PRODUCER_CONFIG, true));
ProducerRecord record = new ProducerRecord<>(ctrlTopic, DataPullConstants.FullPullInterfaceJson.TYPE_VALUE, jsonObj.toString().getBytes());
Future<RecordMetadata> future = producer.send(record);
RecordMetadata meta = future.get();
}
catch (Exception e) {
Log.error("Error occurred when report full data pulling status.", e);
throw new RuntimeException(e);
}
}
示例8: addSystemLog
import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
/**添加係統日誌*/
private void addSystemLog(HttpServletRequest request,ReturnUtil returnUtil, JSONObject handlerJson, String explain) {
JSONObject log = new JSONObject();
JSONObject member = StorageUtil.init(request.getSession()).getLoginMemberInfoJson();
if(member!=null){
log.put("memberId", member.getLong("id"));
}
String ip = DataUtil.getIpAddress(request);
if(!DataUtil.internalIp(ip)){
JSONObject ipJson = new JSONObject();
ipJson.put("ip", ip);
ReturnUtil ip_return = myBaseService.get(null,ipJson, "systemMapper.getIpLibrary");
if(ip_return.getCode()==ReturnUtil.SUCCESS_CODE && ip_return.getResult_data()!=null){
log.put("ip_library_id", ip_return.gDataMap().get("id"));
}else{
JSONObject tbaoIpLibrary = DataUtil.getAddressByIP(ip);
ipJson = tbaoIpLibrary.getJSONObject("data");
ReturnUtil ipLibraryReturn = myBaseService.add(null,ipJson, "systemMapper.addIpLibrary", true);
if(ipLibraryReturn.getCode()==ReturnUtil.SUCCESS_CODE){
log.put("ip_library_id", ipLibraryReturn.getExtend_info());
}
}
}else{
log.put("ip_library_id", -1);
}
String method = handlerJson.getString("beanType")+"."+handlerJson.getJSONObject("method").getString("name");
log.put("handler", method);
log.put("explain", explain);
log.put("have_authority", returnUtil.getCode()==ReturnUtil.SUCCESS_CODE);
log.put("parameter", DataUtil.requestToJson(request).toJSONString());
request.setAttribute(Statics.SYSTEM_LOG_ID, log.toJSONString());
}
示例9: getUserInfo
import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
public static User getUserInfo (int uid, JSONObject object, boolean loadFull) throws APIException {
if (mCachedUsers.containsKey(uid)) {
// TODO: 這裏會緩存 簡短的用戶信息 ,當獲取完整信息時也會取出緩存。
return mCachedUsers.get(uid);
}
try {
JSONObject data = object.getJSONObject("data");
User user = new User();
user.setId(uid);
JSONObject attributes;
if (loadFull) {
attributes = data.getJSONObject("attributes");
} else {
attributes = object.getJSONObject("attributes");
}
user.setUsername(attributes.getString("username"));
user.setAvatarUrl(attributes.getString("avatarUrl"));
if (loadFull) {
user.setBio(attributes.getString("bio"));
user.setJoinTime(attributes.getString("joinTime"));
user.setDiscussionsCount(attributes.getInteger("discussionsCount"));
user.setCommentsCount(attributes.getInteger("commentsCount"));
user.setCanEdit(attributes.getBoolean("canEdit"));
user.setCanDelete(attributes.getBoolean("canDelete"));
user.setCanSuspend(attributes.getBoolean("canSuspend"));
user.setVingleShareSocial(attributes.getString("vingle.share.social"));
//TODO:Group
}
mCachedUsers.put(uid, user);
return user;
} catch (JSONException e) {
throw new APIException(e);
}
}
示例10: getTag
import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
public static Tag getTag (int id, JSONObject object) throws APIException {
if (DEBUG) Log.i(TAG, "-> getTag");
try {
if (mCachedTags.containsKey(id)) {
return mCachedTags.get(id);
}
Tag tag = new Tag();
tag.setId(object.getInteger("id"));
JSONObject attributes = object.getJSONObject("attributes");
tag.setName(attributes.getString("name"));
tag.setDescription(attributes.getString("description"));
tag.setSlug(attributes.getString("slug"));
tag.setColor(Color.parseColor(attributes.getString("color")));
tag.setBackgroundUrl(attributes.getString("backgroundUrl"));
tag.setBackgroundMode(attributes.getString("backgroundMode"));
tag.setIconUrl(attributes.getString("iconUrl"));
tag.setDiscussionsCount(attributes.getInteger("discussionsCount"));
//tag.setPosition(attributes.getInteger("position"));
tag.setDefaultSort(attributes.getString("defaultSort"));
tag.setChild(attributes.getBoolean("isChild"));
tag.setHidden(attributes.getBoolean("isHidden"));
tag.setLastTime(attributes.getString("lastTime"));
tag.setCanStartDiscussion(attributes.getBoolean("canStartDiscussion"));
tag.setCanAddToDiscussion(attributes.getBoolean("canAddToDiscussion"));
mCachedTags.put(id, tag);
return tag;
} catch (JSONException e) {
throw new APIException(e);
}
}
示例11: test_for_alipay
import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
public void test_for_alipay() throws Exception {
File file = new File("/Users/wenshao/Downloads/x.txt");
String text = FileUtils.readFileToString(file);
JSONObject root = JSON.parseObject(text);
JSONObject resultObj = root.getJSONObject("resultObj");
assertNotNull(resultObj);
JSONArray conditionGroupItemList = resultObj.getJSONArray("conditionGroupItemList");
assertNotNull(conditionGroupItemList);
JSONObject conditionGroup = conditionGroupItemList.getJSONObject(0).getJSONObject("conditionGroup");
assertNotNull(conditionGroup);
JSONArray recordList = conditionGroup.getJSONArray("recordList");
assertNotNull(recordList);
JSONArray conditionItemList = recordList.getJSONObject(0).getJSONArray("conditionItemList");
assertNotNull(conditionItemList);
JSONObject condition = conditionItemList.getJSONObject(18).getJSONObject("condition");
assertNotNull(condition);
JSONArray conditionConstraint = condition.getJSONArray("conditionConstraint");
assertNotNull(conditionConstraint);
JSONObject constraintOptionalRecordMap = conditionConstraint.getJSONObject(0).getJSONObject("constraintOptionalRecordMap");
assertNotNull(constraintOptionalRecordMap);
System.out.println(constraintOptionalRecordMap);
}
示例12: parseURLSWithJSONObject
import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
private static List<String> parseURLSWithJSONObject(final JSONObject object) {
final JSONObject range = object.getJSONObject("first_range");
final JSONArray journals = object.getJSONArray("journals");
final String article_type = object.getString("article_type");
final String order = object.getString("order");
return journals.stream()
.map(journal -> concatUrl(range, journal, article_type, order))
.collect(Collectors.toList());
}
示例13: getNodeNameOrId
import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
private static String getNodeNameOrId(int pid,int type) throws IOException {
String selfNodeId = "";
String selfNodeName = "";
String netWorkHost = getNetworkHost(pid);
int port = getHttpPort(pid);
String url = getConnectionUrl(pid) + "/_nodes";
String responseText;
try {
responseText = HttpUtil.get(url).getResult();
} catch (IOException e) {
log.error("訪問{}異常",url,e);
return "";
}
JSONObject responseJSON = JSONObject.parseObject(responseText);
JSONObject nodes = responseJSON.getJSONObject("nodes");
if(nodes != null){
for (Map.Entry<String, Object> entry : nodes.entrySet()) {
String nodeId = entry.getKey();
JSONObject nodeInfo = (JSONObject) entry.getValue();
String nodeName = nodeInfo.getString("name");
String httpAddress = nodeInfo.getString("http_address");
if (StringUtils.isEmpty(httpAddress)) {
selfNodeId = nodeId;
selfNodeName = nodeName;
}else {
if("127.0.0.1".equals(netWorkHost) || "localhost".equals(netWorkHost)){
if(httpAddress.contains("127.0.0.1:" + port) || httpAddress.contains("localhost:" + port)){
selfNodeId = nodeId;
selfNodeName = nodeName;
}
}else{
if(httpAddress.contains(netWorkHost + ":" + port)){
selfNodeId = nodeId;
selfNodeName = nodeName;
}
}
}
}
}else{
log.error("elasticSearch json結果解析失敗:{}",responseText);
}
switch (type){
case 1:
return selfNodeId;
case 2:
return selfNodeName;
default:
return "";
}
}
示例14: test_for_issue
import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
public void test_for_issue() throws Exception {
JSONObject json = new JSONObject();
json.put("robj", "{abc: 123}");
JSONObject robj = json.getJSONObject("robj");
assertEquals(123, robj.get("abc"));
}
示例15: pushNative
import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
@JSMethod
public void pushNative(String encodeParam, JSCallback callback) {
if (TextUtils.isEmpty(encodeParam)) {
return;
}
try {
JSONObject options = JSON.parseObject(encodeParam);
String url = "";
UWXTheme.NavBar navBar = null;
JSONObject param = null;
if (options.containsKey(UWXBundleInfo.KEY_URL)) {
url = options.getString(UWXBundleInfo.KEY_URL);
}
if (options.containsKey(UWXBundleInfo.KEY_NAV_BAR)) {
String _navBar = options.getString(UWXBundleInfo.KEY_NAV_BAR);
if (!TextUtils.isEmpty(_navBar)) {
navBar = JSON.parseObject(_navBar, UWXTheme.NavBar.class);
}
}
if (options.containsKey(UWXBundleInfo.KEY_PARAM)) {
param = options.getJSONObject(UWXBundleInfo.KEY_PARAM);
}
UWLog.v("params=" + encodeParam);
if (!TextUtils.isEmpty(url)) {
UWXNavigatorAdapter navigatorAdapter = UWXSDKManager.getInstance().getNavigatorAdapter();
if (navigatorAdapter != null) {
navigatorAdapter.pushNative((Activity) mWXSDKInstance.getContext(),url ,param);
if (callback != null) {
callback.invoke(MSG_SUCCESS);
}
}
} else {
callback.invoke(MSG_FAILED);
}
} catch (Exception e) {
WXLogUtils.eTag(TAG, e);
if (callback != null) {
callback.invoke(MSG_FAILED);
}
}
}