Home>

First, the front desk

// convert to object
var myobject=json.parse (_data);
alert ("Object:" + myobject.msg);
// convert to array
var myobj=eval ("[" + _ data + "]");
for (var i=0;i<myobj.length;i ++) {
alert ("Array:" + myobj [i] .msg);
}
// Convert json formatted string to json object
var json1="{" department ":" Zhongbing "," address ":" Beijing "," contacts ":" "," telphone ":" 15201274666 "," email ":" [email protected] " , "fax":"0108596666"} ";
var json2="{" department ":" Zhongbing 2 "," address ":" Beijing 2 "," contacts ":" 2 "," telphone ":" 152012746662 "," email ":" [email protected] .net "," fax ":" 01085966662 "}";
var jsonobj=$.parsejson (json1);or use the eval method
// Convert the array into a json object
var arr=new array ();
arr.push (json1);
arr.push (json2);
var b=json.stringify (arr)

Backstage

When you need to turn a string into a json array and iterate through its contents.

Home import net.sf.json.jsonarray and net.sf.json.jsonobject two jar packages

string str="[{name:" a ", value:" aa "}, {name:" b ", value:" bb "}, {name:" c ", value:" cc "}, {name:"d", value:"dd"}] ";// an untransformed string
jsonarray json=jsonarray.fromobject (str);// first convert the string into a jsonarray object
if (json.size ()>0) {
 for (int i=0;i<json.size ();i ++) {
  jsonobject job=json.getjsonobject (i);// traverse the jsonarray array and turn each object into a json object
  system.out.println (job.get ("name") + "=");// get the attribute value in each object
 }
}
  • Previous arcgis for js modify infowindow style
  • Next In-depth explain the refactoring SqlSessionFactoryBean integration of Mybatis and Spring (on)
  • Trends