我正在尝试解析JSON字符串,但是当我这样做时,我得到了未定义.
var codes = jQuery.parseJSON(response);
$.each(codes, function (key, value) {
alert(value.Display);
});
Run Code Online (Sandbox Code Playgroud)
以下是codes变量的内容:
["{ Display = string1, Sell = string2 }",
"{ Display = string1, Sell = string2 }"]
Run Code Online (Sandbox Code Playgroud)
警报返回值undefined.显示为.我期待"String1".我究竟做错了什么?
小智 6
那不是有效的JSON字符串.
正确的字符串看起来像这样:
'{ "Display": "string1", "Sell": "string2" }'
Run Code Online (Sandbox Code Playgroud)