举例说明:
var path = "<%=path%>";
var categoryJson ="[{'name':'kevin','age':25},{'name':'cissy','age':24}]";
$post(path+'/test/helloworldmyJson='+categoryJson);
通过post方式把myJosn传到java。
java层的处理:
String[] params1 = (String[]) parametersget("myJson");//接收myJson参数
String json = new String(params1[0]);
Systemoutprintln(json);
Gson gson = new Gson();
String jso1n = gsontoJson(json);
Systemoutprintln(jso1n);
JsonParser pa = new JsonParser();
JsonArray arr = paparse(json)getAsJsonArray();
Iterator it = arriterator();
while(ithasNext()){
Systemoutprintln(itnext());
是 documentgetElementsByName 吧?
另外如果是在IE9或IE9以下,无论表单元素是写name属性或是id属性都会取得到值。
例如
<!doctype html><html>
<head>
<title></title>
<script type="text/javascript">
windowonload = function(){
var value =documentgetElementsByName("a");
var result = [];
for(var i =0;i<valuelength;i++){
resultpush(value[i]value);
}
consolelog( resultjoin(","));
}
</script>
</head>
<body>
<input type="text" name="a" value="3"/>
<input type="text" id="a" value="2"/>
<input type="text" name="a" value="4"/>
<input type="text" name="a" value="5"/>
</body>
</html>
在当前版本的 opera,ff,chrome,IE10,IE11中获取的值是 3,4,5,但是在IE9及IE9一下版本获取的是 3,2,4,5
PHP接收JSON格式的数据在API服务中,目前流行采用json形式来交互。
给前端调用的接口输出Json数据,这个比较简单,只需要组织好数据,用json_encode($array) 转化一下,前端就得到json格式的数据。
接收前端提交的json数据稍微复杂一点,原因是:PHP默认识别的数据类型是application/x-['>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)