java从页面传回来的json格式是这样的,我怎么获取到里面的deleted实现删除功能,求大神帮忙。 JAVA后台如何解析和获取JSP页面传过来的JSON格式的数...
\u5173\u4e8e java\u5728\u540e\u53f0\u4f20\u4e00\u4e2ajson\u6570\u636e\u5230\u524d\u53f0\u7684\u95ee\u9898\u4ece\u4f60\u4f20\u7684json\u6765\u770b\uff0c\u4f60\u4f20\u56de\u7684sessionModel\u4ec5\u4ec5\u662f\u4e00\u4e2a\u5b57\u7b26\u4e32\uff0c\u5e76\u4e0d\u662f\u5305\u542b\u5bf9\u8c61\u7684\u7ed3\u6784\u4f53\uff0c\u6240\u4ee5\u4f60\u53d6\u4e0d\u5230\u7c7b\u6210\u5458\u7684\uff0c\u5982\u679csessionModel\u662f\u4e00\u4e2a\u5bf9\u8c61\uff0c\u90a3\u4e48\u76f8\u5e94\u7684\u5b57\u7b26\u4e32\u5e94\u8be5\u7c7b\u4f3c\u5982\u4e0b\u7ed3\u6784
{\u201cmodel\u201d:{"sessionModel":{"id":"1","name","lz"}}}
\u901a\u8fc7 JSONObject\u7c7b\u5c31\u53ef\u4ee5\u4e86
\u9996\u5148 \u4f60\u628a\u8fd9\u51e0\u4e2a\u5305 \u4e0b\u4e0b\u6765 \u653e\u5230\u4f60\u9879\u76ee\u3002\u5982\u679c\u6709\u5c31\u4e0d\u8981\u4e0b\u4e86\uff1a
1.commons-lang.jar
2.commons-beanutils.jar
3.commons-collections.jar
4.commons-logging.jar
5.ezmorph.jar
6.json-lib-2.2.2-jdk15.jar
\u50cf\u4f60\u8fd9\u79cd\u662f\u6570\u636e\u5f62\u5f0f \u5c31\u901a\u8fc7 JSONArray \u5982\uff1a
JSONArray datasJson = JSONArray.fromObject(datas);\u6700\u597d\u628adatas toString \u4e00\u4e0b
你使用什么json包?不同的json包,操作不一样
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
public class JsonLib
{
public static void main(String[] args)
{
String str = "{\"data\":{\"month\":\"4\",\"allData\":{\"deleted\":[{\"guid\":\"4\",\"tableName\":\"ON\"}]}}}";
JSONObject object = JSONObject.fromString(str);
JSONObject data = object.getJSONObject("data");
JSONObject allData = data.getJSONObject("allData");
JSONArray deleted = allData.getJSONArray("deleted");
for(int i = 0; i < deleted.length(); i++)
{
JSONObject dobj = deleted.getJSONObject(i);
System.out.println(dobj.get("guid"));
System.out.println(dobj.get("tableName"));
}
}
}
绛旓細public class JsonToMapTest01 { public static void main(String[] args){ String str = "{\"0\":\"zhangsan\",\"1\":\"lisi\",\"2\":\"wangwu\",\"3\":\"maliu\"}";//绗竴绉嶆柟寮 Map maps = (Map)JSON.parse(str);System.out.println("杩欎釜鏄敤JSON绫绘潵瑙f瀽JSON瀛楃涓!!!
绛旓細import net.sf.json.JSONArray;import net.sf.json.JSONObject;public class JsonLib{public static void main(String[] args){String str = "{\"data\":{\"month\":\"4\",\"allData\":{\"deleted\":[{\"guid\":\"4\",\"tableName\":\"ON\"}]}}}";JSONObject object = JSONOb...
绛旓細JSONObject json = JSONObject.fromObject(map,jc);鐒跺悗鍔燡SONObject json = JSONObject.fromObject(map,jc);杩欏彞鍟婏紝鍗曠函鐢⊿ONObject json = JSONObject.fromObject(map);鏄洿鎺ユ妸map瀵硅薄鐨勬墍鏈夊睘鎬ч兘杞崲鍒癹son瀵硅薄涓紝鍔犱釜JSONConfig鏄负浜嗚兘鍙夊彲鎺х殑鎶妋ap瀵硅薄杞崲鎴恓son瀵硅薄锛宻avefile鏄竴涓狥ile瀵...
绛旓細1.commons-lang.jar 2.commons-beanutils.jar 3.commons-collections.jar 4.commons-logging.jar 5.ezmorph.jar 6.json-lib-2.2.2-jdk15.jar 鍍忎綘杩欑鏄暟鎹舰寮 灏遍氳繃 JSONArray 濡傦細JSONArray datasJson = JSONArray.fromObject(datas);鏈濂芥妸datas toString 涓涓 ...
绛旓細鍦↗ava涓紝鍙互浣跨敤Jackson搴撳皢Java瀵硅薄杞崲涓篔SON鏍煎紡銆備緥濡傦紝鍋囪鏈変竴涓悕涓簆erson鐨凱erson瀵硅薄锛屽彲浠ヤ娇鐢ㄤ互涓嬩唬鐮佸皢鍏惰浆鎹负JSON鏍煎紡锛歩mport com.fasterxml.jackson.databind.ObjectMapper;ObjectMapper mapper = new ObjectMapper();String json = mapper.writeValueAsString(person);杩欐浠g爜涓紝ObjectMapper...
绛旓細浜屻java瑙f瀽JSON姝ラ A銆佹湇鍔″櫒绔皢鏁版嵁杞崲鎴恓son瀛楃涓 棣栧厛銆佹湇鍔″櫒绔」鐩瀵煎叆json鐨jar鍖呭拰json鎵渚濊禆鐨刯ar鍖呰嚦builtPath璺緞涓嬶紙杩欎簺鍙互鍒癑SON-lib瀹樼綉涓嬭浇锛歨ttp://json-lib.sourceforge.net/锛夌劧鍚庡皢鏁版嵁杞负json瀛楃涓诧紝鏍稿績鍑芥暟鏄細public static String createJsonString(String key, ...
绛旓細json浠ラ敭鍊煎鏉ヨ〃绀烘暟鎹傛瘡涓艰涓涓敭鍚嶅瓧寮曠敤锛堥敭鍚嶅瓧鏄釜string锛夈傚鏋滀綘鎯充互json琛ㄧず浜哄悕锛屼粬浠殑鍚嶅瓧灏嗚"name"閿紩鐢紝濡備笅锛氣渘ame鈥 : 鈥淛ames鈥濇墍浠son鐢ㄤ竴绉嶅鏄撹搴旂敤绋嬪簭浼犻掔殑鏂瑰紡琛ㄧ幇鏁版嵁锛岄潪甯稿畬缇庛傛墍浠ュ綋浠巜ebservice瑙f瀽鏁版嵁鏃讹紝浣犺鍋氱殑绗竴浠朵簨灏辨槸鎼炴竻妤氫綘鐨勬ā鍨嬨備笅闈㈡垜浠細...
绛旓細澶勭悊鍩烘湰鐨java瀵硅薄浣跨敤JSONObject绫伙紝鐢ㄦ硶澶т綋濡備笅锛歱ublic void testMap(){ Map<String,Object> map = new HashMap<String,Object>();map.put("name", "qiu");map.put("password", "123");map.put("address", "china");User user = new User();user.setUserName("qiuqiu");user.set...
绛旓細鍙互鐩存帴鍦ㄨ繑鍥炵殑鏂规硶涓婃坊鍔燖ResponseBody 瀹炵幇瀵硅薄鑷姩杞崲json鏍煎紡 RequestMapping(value = "/get") @ResponseBodypublic Object getJson() { Map<String, Object> map = new HashMap(); map.put("name", "dhweicheng"); map.put("age", 25); return map;} ...
绛旓細浣犲彲鑳芥湁鐐规悶娣蜂簡銆備綘鐨刣ataType:html,鐨勮瘽鏄棤娉曟帴鏀跺悗鍙颁紶鐨刯son涓茬殑銆傜敱浜庝綘鍚庡彴return "wanglongtest.html"锛屾墍浠ュ墠鍙癮jax鎺ユ敹鏄竴涓 html瀵硅薄锛屽垯鍓嶅彴鍙互鎸夊涓嬩唬鐮佸鐞嗭細success: function(rs){ ("#testDiv").html(rs);} html:<!-- ajax 瑕佸~鍏呯殑鍐呭 --> --- 濡傛灉浣犳兂鎺ユ敹鍚庡彴鐨...