js中json的创建和调用
2016-07-22 11:37
363 查看
var jn={
"search":{
"textValue":"1",
"object":{
"textValue":"1"
},
"type":{
"textValue":"1"
},
"id":{
"textValue":"1"
},
"query":{
"fatherid":"",
"relation":"",
"textValue":"1",
"id":{
"textValue":"1"
},
"name":{
"textValue":"1"
},
"filter":{
"relation":"",
"textValue":"1",
"operation":{
"textValue":"1"
},
"input":{
"textValue":"1",
}
},
"columns":{
"textValue":"1",
"column":{
"textValue":"1"
}
},
"storage":{
"textValue":"1",
"storetype":{
"textValue":"1"
},
"source":{
"textValue":"1"
}
}
},
"result":{
"textValue":"1",
"sort":{
"sortway":"",
"textValue":"1",
"sortitem":{
"textValue":"1",
"weight":""
}
},
"group":{
"textValue":"1",
"column":{
"textValue":"1"
}
},
"data":{
"textValue":"1",
"column":{
"textValue":"1"
}
},
"limit":{
"textValue":"1",
"offset":{
"textValue":"1"
},
"rows":{
"textValue":"1"
}
}
}
}
};
// 在这里时jn变量不是json对象,它只是一个普通的obj对象。
var str=JSON.stringify(jn);
// 在这里我们把jn的obj转成了json的字符串形式,
console.info(str);
json=JSON.parse(str);
// 在这里我们把转好的json字符串变成json对象
console.info(json);
//
这个是能转成json的字符串形式。
var s="{\"dd\":{\"ss\":\"ww\",\"ee\":\"rr\"}}";
//将字符串变成json
json=JSON.parseJSON(json);
//
这个是能转成json的字符串形式。
var s='{"dd":{"ss":"ww","ee":"rr"}}';
//将字符串变成json
json=JSON.parseJSON(json); 报错,不能转为json,因为它不认识'。只认识"
"search":{
"textValue":"1",
"object":{
"textValue":"1"
},
"type":{
"textValue":"1"
},
"id":{
"textValue":"1"
},
"query":{
"fatherid":"",
"relation":"",
"textValue":"1",
"id":{
"textValue":"1"
},
"name":{
"textValue":"1"
},
"filter":{
"relation":"",
"textValue":"1",
"operation":{
"textValue":"1"
},
"input":{
"textValue":"1",
}
},
"columns":{
"textValue":"1",
"column":{
"textValue":"1"
}
},
"storage":{
"textValue":"1",
"storetype":{
"textValue":"1"
},
"source":{
"textValue":"1"
}
}
},
"result":{
"textValue":"1",
"sort":{
"sortway":"",
"textValue":"1",
"sortitem":{
"textValue":"1",
"weight":""
}
},
"group":{
"textValue":"1",
"column":{
"textValue":"1"
}
},
"data":{
"textValue":"1",
"column":{
"textValue":"1"
}
},
"limit":{
"textValue":"1",
"offset":{
"textValue":"1"
},
"rows":{
"textValue":"1"
}
}
}
}
};
// 在这里时jn变量不是json对象,它只是一个普通的obj对象。
var str=JSON.stringify(jn);
// 在这里我们把jn的obj转成了json的字符串形式,
console.info(str);
json=JSON.parse(str);
// 在这里我们把转好的json字符串变成json对象
console.info(json);
//
这个是能转成json的字符串形式。
var s="{\"dd\":{\"ss\":\"ww\",\"ee\":\"rr\"}}";
//将字符串变成json
json=JSON.parseJSON(json);
//
这个是能转成json的字符串形式。
var s='{"dd":{"ss":"ww","ee":"rr"}}';
//将字符串变成json
json=JSON.parseJSON(json); 报错,不能转为json,因为它不认识'。只认识"
相关文章推荐
- javascript 引用类型 - Array迭代
- js实现url链接encode加密
- javascript 获取iframe元素的方法
- javascript预编译原理和例子
- JavaScript中textRange对象使用方法总结(IE only!)
- JavaScript判断浏览器版本(未测试)
- JavaScript验证手机号码代码简单代码实例(未测试)
- js各种模式的自定义对象
- videojs播放器插件
- js
- Gson解析和json解析
- 如何解决wow.js与fullpage的兼容性
- Json和Xml数据解析
- jsp中字段截取
- js中replace的用法
- JavaScript 正则表达式
- javascript数组的方法总结,非常实用的!
- Jsp页面中双引号问题
- js 当前日期及时间
- javascript中的方法:类方法(静态方法)对象方法 原型方法