没事写个JSON

JS方法:
<html>
<head>
<script>
function loadMe(){
var map = [
{"name":"king","address":"HuNan"},
{"name":"marko","address":"GungDong"},
{"name":"even","address":"HeNan"}
];
for(var i in map){
alert(map[i].name);
}
}
</script>
</head>
<body onLoad="loadMe();">

</body>
</html>

JAVA方法:
----------------------------------------
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

public class JsonTest {
public static void main(String[] args){
String[] boolArray = new String[]{"ss","dd","ff"};  
JSONArray jsonArray = JSONArray.fromObject( boolArray );
System.out.println(jsonArray);

JSONObject jsonObject = new JSONObject();
JSONArray jsonArray1 = new JSONArray();

jsonObject.put("name", "king");
jsonObject.put("address", "HuNan");
jsonArray1.add(jsonObject);

jsonObject.put("name", "marko");
jsonObject.put("address", "GungDong");
jsonArray1.add(jsonObject);

jsonObject.put("name", "even");
jsonObject.put("address", "HeNan");
jsonArray1.add(jsonObject);

Object[] objs = jsonArray1.toArray();
for(int i=0;i<objs.length;i++){
System.out.println("obj==========="+objs[i]);
}
}
}

你可能感兴趣的:(json,.net)