当前位置: 代码迷 >> JavaScript >> JSON小结
  详细解决方案

JSON小结

热度:114   发布时间:2012-12-18 12:43:41.0
JSON总结
a> 将页面的复杂数据传递到后台

request.result
{
        "recordId":"39885",
        "recordName":"Record Name: host_node",
        "recordType":"Record Type: CI",
        "forSimulate":"false",
        "attributes":
        [
                {"name":"TenantOwner","value":"CALI"},
                {"name":"data_externalid","value":"20110422_pass"},
                {"name":"node_model","value":"AIX 6.1.3.0"},
                {"name":"data_origin","value":"20110422_unmatched_on_adapter"},
                {"name":"vendor","value":"3COM"}
        ]
}


b> 后台用JSON的方式解析,并放到list<Bean>中
public static void main(String[] args) throws Exception {
		
		JSONParser parser = new JSONParser();
		// {"currentSelectedId":39855,"allSelectedIds":["39855","39856","39857"]}
		String s = "{\"currentSelectedId\":39855,\"allSelectedIds\":[\"39855\",\"39856\",\"39857\"]}";

		JSONObject selectedRecordsJson = (JSONObject) parser.parse(s);
		JSONArray arrays = (JSONArray) selectedRecordsJson.get("allSelectedIds");
		for (int i = 0; i < arrays.size(); i++) {
			System.out.println(arrays.get(i));
		}
		
	}

c> JSON总结: 太过于麻烦,用struts2来做的话会好很多。


注 公司的CIM中 得到的 postData值是
selectedRecords={
	"currentSelectedId":282906,
	"allSelectedIds":["282906"]
}
&
result={
	"recordId":"282906",
	"recordName":"Record Name: connection",
	"recordType":"Record Type: Relationship",
	"forSimulate":"false",
	"attributes":[{
		"name":"source_citype",
		"value":"11"},{
				"name":"destination_citype",
				"value":"unix"
		},{
				"name":"data_externalid",
				"value":"connection-0704-aa1000011"
		},{
				"name":"source_ciexternalid",
				"value":"asset-0704-aa100000eee"
		},{
				"name":"data_origin",
				"value":"test"
		},{
				"name":"destination_ciexternalid",
				"value":"unix-0704-y2e3eee"
		}]
}
  相关解决方案