我想用Ext.decode( string )在extjs4中解码,里面有json字符串的json字符串,就像这样:
var string = "{success:true,
rows:[{"jsonfields":"[
{\\"name\\":\\"cm:title\\",\\"title\\":\\"Titolo\\",\\"description\\":\\"Titolo del contenuto\\",\\"dataType\\":\\"d:mltext\\",\\"url\\":\\"\/api\/property\/cm_title\\"},
{\\"name\\":\\"cm:content\\",\\"title\\":\\"Contenuto\\",\\"description\\":\\"Contenuto\\",\\"dataType\\":\\"d:content\\",\\"url\\":\\"\/api\/property\/cm_content\\"},
{\\"name\\":\\"cm:name\\",\\"title\\":\\"Nome\\",\\"description\\":\\"Nome\\",\\"dataType\\":\\"d:text\\",\\"url\\":\\"\/api\/property\/cm_name\\"}]"}
]}";如您所见,“jsonfield”是一个json字符串代码。如何用Ext.decode( string )解码这个字符串有什么建议吗?
发布于 2012-06-09 03:06:53
您的JSON代码有几个问题。
下面是正确的JSON代码。我也更新了你的jsfiddle链接。
var string = '{
"success": true,
"rows": [
{
"jsonfields": [
{
"name": "cm: title",
"title": "Titolo",
"description": "Titolodelcontenuto",
"dataType": "d: mltext",
"url": "/api/property/cm_title"
},
{
"name": "cm: content",
"title": "Contenuto",
"description": "Contenuto",
"dataType": "d: content",
"url": "/api/property/cm_content"
},
{
"name": "cm: name",
"title": "Nome",
"description": "Nome",
"dataType": "d: text",
"url": "/api/property/cm_name"
}
]
}
]}';
var decodedString = Ext.decode(string);
console.log(decodedString);
发布于 2012-06-08 20:37:19
这是用Ext解码JSON的正确方法,异常可能会告诉您JSON字符串中的一些无效语法。JSON format非常严格。
您可以使用jsonlint之类的在线验证器来帮助找出语法的错误所在。
另一个注意事项:在这种情况下,在字符串两边使用单引号通常更容易,这样就可以嵌入双引号,而不必转义它们。
var string = '{ "success": true, ...}'https://stackoverflow.com/questions/10945405
复制相似问题