81,091
社区成员
发帖
与我相关
我的任务
分享
var activity_data = {
"53042801" : [ {
"name" : "",
"geoGoord" : [ 200, 350 ],
"value" : 1
}, {
"name" : "",
"geoGoord" : [ 360, 580 ],
"value" : 1
} ],
"53042802" : [ {
"name" : "",
"geoGoord" : [ 60, 250 ],
"value" : 1
}, {
"name" : "",
"geoGoord" : [ 290, 230 ],
"value" : 1
} ]
};
package com;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.Iterator;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
public class test1 {
@SuppressWarnings("unchecked")
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new FileReader(
"E:\\Test1\\src\\com\\js.js"));
// 获取js中的数据内容
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line);
}
reader.close();
// 解析数据内容,获取json数据,具体情况具体解析
String jsonString = sb.substring(sb.indexOf("{"),
sb.lastIndexOf("}") + 1);
JSONObject jo = JSONObject.fromObject(jsonString);
Iterator it = jo.keys();
while (it.hasNext()) {
String key = (String) it.next();
String value = jo.getString(key);
JSONArray json = JSONArray.fromObject(value);
for (int i = 0; i < json.size(); i++) {
JSONObject job = json.getJSONObject(i);
System.out.println(job.getString("geoGoord"));
}
}
}
}
public static String getFileContent(File f) throws Exception
{
FileInputStream input=new FileInputStream(f);
ByteArrayOutputStream out=new ByteArrayOutputStream();
byte[] b=new byte[1024*5];
int n=0;
while((n=input.read(b))>=0)
{
out.write(b, 0, n);
}
return out.toString("UTF-8");
}
public static void main(String[] args)
{
try
{
String content=getFileContent(new File("c:/11.js"));//js物理路径 读取js内容
System.out.println(content);
String data=content.split("=")[1];
JSONObject json=new JSONObject(data);
} catch (Exception e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
var vo = {
id:id,
name:temName,
}
var url = "/save.do";
$.ajax({
url : url,
type : 'post',
contentType: "application/json",
data :JSON.stringify(vo),
success:function(){
$.MsgBox.Alert("保存成功");
},
error:function(){
$.MsgBox.Alert("保存失败");
}
});
后端接收的代码
@RequestMapping(value = "/save.do")
@ResponseBody
public String save(@RequestBody FarmTemplate vo) {
JSONObject json = new JSONObject();
try {
if (null == vo.getId()) {
fService.save(vo);
} else {
fService.edit(vo);
}
requestSucc(json);
} catch (Exception e) {
log.error(e.getMessage(), e);
requestFail(json, e);
}
return json.toString();
}
他会识别vo这个实体类的属性自动拼接的