本文整理匯總了Java中com.alibaba.fastjson.JSONObject.parse方法的典型用法代碼示例。如果您正苦於以下問題:Java JSONObject.parse方法的具體用法?Java JSONObject.parse怎麽用?Java JSONObject.parse使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.alibaba.fastjson.JSONObject
的用法示例。
在下文中一共展示了JSONObject.parse方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: parseJson
import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
Object parseJson(String data,Options.Type type){
if( type == Options.Type.json){
return JSONObject.parse(data);
}else if( type == Options.Type.jsonp){
if(data == null || data.isEmpty()) {
return new JSONObject();
}
int b = data.indexOf("(")+1;
int e = data.lastIndexOf(")");
if(b ==0 || b >= e || e <= 0){
return new JSONObject();
}
data = data.substring(b,e);
return JSONObject.parse(data);
}else {
return data;
}
}
示例2: parseData
import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
Object parseData(String data, Options.Type type) throws JSONException{
if( type == Options.Type.json){
return JSONObject.parse(data);
}else if( type == Options.Type.jsonp){
if(data == null || data.isEmpty()) {
return new JSONObject();
}
int b = data.indexOf("(")+1;
int e = data.lastIndexOf(")");
if(b ==0 || b >= e || e <= 0){
return new JSONObject();
}
data = data.substring(b,e);
return JSONObject.parse(data);
}else {
return data;
}
}
示例3: process
import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
@Override
public void process(Page page) {
List<String> url_list = new ArrayList<>();
List<String> name_list = new ArrayList<>();
JSONObject jsonObject = (JSONObject) JSONObject.parse(page.getRawText());
JSONArray data = (JSONArray) jsonObject.get("imgs");
for(int i=0;i<data.size();i++){
String url = (String) data.getJSONObject(i).get("objURL");
String name = (String) data.getJSONObject(i).get("fromPageTitleEnc");
if(url!=null){
url_list.add(url);
name_list.add(name);
}
}
setUrls(url_list);
setNames(name_list);
}
示例4: 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);
}
示例5: init
import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
public void init() {
Map<String, Map<String, String>> map = new ConcurrentHashMap<String, Map<String, String>>();
try {
List<String> viewList = zkConn.getChildren().forPath(KVPathUtil.getViewPath());
for (String singlePath : viewList) {
String[] paths = singlePath.split("/");
String jsonData = new String(zkConn.getData().forPath(KVPathUtil.getViewPath() + SEPARATOR + singlePath), "UTF-8");
JSONObject obj = (JSONObject) JSONObject.parse(jsonData);
String createSql = obj.getString(CREATE_SQL);
String schema = paths[paths.length - 1].split(SCHEMA_VIEW_SPLIT)[0];
String viewName = paths[paths.length - 1].split(SCHEMA_VIEW_SPLIT)[1];
if (map.get(schema) == null) {
map.put(schema, new ConcurrentHashMap<String, String>());
}
map.get(schema).put(viewName, createSql);
}
} catch (Exception e) {
LOGGER.info("init viewData from zk error : " + e.getMessage());
} finally {
viewCreateSqlMap = map;
}
}
示例6: request
import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
public String request(String ip) {
Map<String, String> params = new LinkedHashMap<>();
params.put("ip", ip);
params.put("format", "json");
String url = UrlUtils.build(XIN_LANG_IP_ADDRESS, params);
Map<String, String> headerparams = new HashMap<>(1 << 4);
String response1 = null;
try {
response1 = HttpClientUtils.getMethodGetResponse(url);
} catch (Exception e) {
LOGGER.error("response {} return is not 200, param_json {}", response1, ip);
return "火星小朋友";
}
Object object = JSONObject.parse(response1);
if(object instanceof Integer){
return "火星小朋友";
}
JSONObject jsonObject = (JSONObject) object;
String country = jsonObject.getString("country") != null ? jsonObject.getString("country") : "";
String province = jsonObject.getString("province") != null ? jsonObject.getString("province") : "";
String city = jsonObject.getString("city") != null ? jsonObject.getString("city") : "";
return country + province + "的網友";
}
示例7: parseWithNotExistType
import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
@Test
public void parseWithNotExistType() {
String s = "{\"@type\":\"com.alibaba.fastjson.ValueBean\",\"val\":1}";
Object object = JSONObject.parse(s);
Assert.assertNotNull(object);
Assert.assertTrue(object instanceof JSONObject);
Assert.assertEquals(new Integer(1), JSONObject.class.cast(object).getInteger("val"));
}
示例8: parseWithExistType
import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
@Test
public void parseWithExistType() {
String s = "{\"@type\":\"com.alibaba.fastjson.deserializer.ValueBean\",\"val\":1}";
Object object = JSONObject.parse(s);
Assert.assertNotNull(object);
Assert.assertTrue(object instanceof ValueBean);
Assert.assertEquals(new Integer(1), ValueBean.class.cast(object).getVal());
}
示例9: skipByName
import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
public static JSONObject skipByName(Object data, Set<String> propertySet) {
JSONObject req = (JSONObject) JSON.toJSON(data);
SerializerUtil serializer = new SerializerUtil(null, propertySet, null, null);
if(null != propertySet) {
return (JSONObject) req.parse(req.toJSONString(req, serializer.propertyfilter));
}
return req;
}
示例10: encryptionByName
import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
public static JSONObject encryptionByName(HttpSession session, Object data, Set<String> valueSet, boolean encryption) {
JSONObject req = (JSONObject) JSON.toJSON(data);
SerializerUtil serializer = new SerializerUtil(session, null, valueSet, encryption);
if(null != valueSet) {
return (JSONObject) req.parse(req.toJSONString(req, serializer.valuefilter));
}
return req;
}
示例11: getDataFromAPI
import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
private Object getDataFromAPI (String params) {
if (IS_DEBUG) {
System.out.println("params:" + params);
}
String resultHtml = null;
if ("get".equalsIgnoreCase(method)) {
resultHtml = HttpRequest.sendGet(url, connectTimeout, readTimeout, params);
} else if ("post".equalsIgnoreCase(method)) {
resultHtml = HttpRequest.sendPost(url, connectTimeout, readTimeout, params);
} else {
return "暫不支持"+ method +"方法";
}
if (IS_DEBUG) {
System.out.println("result:" + resultHtml);
}
if ("string".equalsIgnoreCase(returnType)) {
return resultHtml;
}
if ("json".equalsIgnoreCase(returnType)) {
return JSONObject.parse(resultHtml);
}
if ("jsonarray".equalsIgnoreCase(returnType)) {
return JSONArray.parse(resultHtml);
}
return "暫不支持返回" + returnType + "類型";
}
示例12: toObject
import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
public static Object toObject(byte[] objectBytes) throws Exception {
return JSONObject.parse(new String(objectBytes));
}
示例13: deserialize
import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
public static<T> T deserialize(byte[] json,Class<T> cls){
return (T) JSONObject.parse(json, Feature.OrderedField);
}