EDIT: I've gotten the "famous question" badge with this question, so I figured I'd come back to it and stick what happened to me right at the very tippy top for people searching it to get an answer right away.
基本上,我是JSON新手.JSON是一个对象(显然),因为它包含各种各样的东西!所以我想"嘿,javascript,用所有这些JSON数据弹出一个alert ",希望它把JSON数据作为字符串提供给我.但javascript并不能做到这一点(这很好!),就像"嘿,这就是我们显示对象的方式,[对象]".
What I could've done is something like alert(obj.DATA[0][1])
and it would've shown me that bit of the object.
我真正想要的是验证我是否制作了良好的JSON数据,我可以用JSON.stringify
判断.
Anyway, back to our regularly scheduled questions!
我试图通过ajax调用获取一些JSON数据,但jQuery似乎不喜欢我的JSON.
如果我这样做:
function init2() {
alert("inside init2");
jQuery.ajax({
url: "/Mobile_ReportingChain.cfm",
type: "POST",
async: false,
success: function (data) {
alert(data);
var obj = jQuery.parseJSON(data);
alert(obj);
}
});
}
我从alert (数据)中得到:
{"COLUMNS":["MFIRST_NAME","MLAST_NAME","MMDDL_NAME","MEMPLY_ID","MAIM_NBR","EMPLY_ID"],
"DATA":[
["FNAME1 ","LNAME1 ","MI1 ","000-14-7189","026-0010","000-62-7276"]
,["FNAME2 ","LNAME2 ","MI2 ","000-01-2302","101-1850","000-14-7189"]
,["FNAME3 ","LNAME3 ","MI3 ","000-91-3619","102-1000","000-01-2302"]
,["FNAME4 ","LNAME4 ","MI4 ","000-25-9687","102-1000","000-91-3619"]
]}
JSONLint说它是有效的json.不过,alert(Obj)给我提供了以下内容:
[object Object]
adding dataType: "json"
or "text json"
just makes it report [object Object]
at alert(data)
.
I'd really like to get this figured out, does anyone know why it's doing this? I'm pretty new at jQuery, my goal is to get an array for each of the columns. The same code I'm using has worked on a different page it looks like, which is what's bothering me the most.