-----------java将json解析为字符串格式-------------------------
public static String toStringSaveGoods(String jsonString) throws JSONException {
JSONObject jsonObject = JSONObject.fromObject(jsonString);
// JSONArray results = jsonObject.getJSONArray("");
Date time=new Date();
// Map result = new HashMap();
Iterator iterator = jsonObject.keys();
String key = null;
String value = null;
String resultS="";
String a0="";
String mid = "";
String amid = "";
String goodsName="";
String isnew="";
while (iterator.hasNext()) {
key = (String) iterator.next();
value = jsonObject.getString(key);
if("auid".equals(key)){
a0=value;
}
if("mid".equals(key)){
mid=value;
}
if("amid".equals(key)){
amid=value;
}
if("goodsName".equals(key)){
goodsName=value;
}
if("isnew".equals(key)){
isnew=value;
}
}//商品总数[a0 mid amid]
resultS = "{a0:'"+a0+"',mid:'"+mid+"',amid:'"+amid+
"',i0:'"+0+"',i1:'"+""+"',i9:'"+10+"',M0:'MMS"+"',M9:'"+time.getTime()+"'}";
return resultS;
}
------------------------jsp页面对于json字符串的解析---------------------------------
$.ajax({
type:"post",
url:"action",
data:{},
success:function(data){
var jsonStr=data;
var list= eval( "(" + jsonStr + ")" );;
length = list.length;
var ul = document.getElementById("myul");
for ( var i = 0; i < list.length; i++) {
ul.innerHTML+='<li>'+list[i]["key"]+'</li>'
}
}