Json将每个字符作为单独的对象返回?

我有一个json对象,我正在使用JSON API插件从wordpress加载。 当我加载json对象并尝试注销它的部分时,似乎它将每个单个字符视为自己的对象,因此循环返回了几千个对象,所有对象都是单个字符。 这是我第一次使用json所以idk如果我在这里错过了一步。 这是我到目前为止使用的代码。

function getProjInfo(theId){ $.ajax({// calling the ajax object of jquery type: "GET",// we are going to be getting info from this data source url: 'http://testing.charter21.com/api/get_post/?post_id='+ theId,//the datasource dataType: "application/json", success: function(data){ parseJson(data); }, // what happens when it is successful at loading the XML error: function(){ alert("error"); } }); }//end of the function function parseJson(inData){ postInfo = inData; $.each(postInfo, function(index, value){ console.log(this); }); } 

json看起来像这样:
{
"status": "ok",
"count": 10,
"count_total": 19,
"pages": 2,
"posts": [
{
"id": 175,
"type": "post",
"slug": "home-page-slider",
"url": "http:\/\/testing.charter21.com\/uncategorized\/home-page-slider\/",
"status": "publish",
"title": "Home Page slider",
"title_plain": "Home Page slider",
"content": "

The cImages in here are the images that are in the slider on the home page this content in this box will not show up. Its only here as a guide.\n",
"excerpt": "The cImages in here are the images that are in the slider on the home page this content in this box will not show up. Its only here as a guide.",
"date": "2011-01-25 10:40:25",
"modified": "2011-01-25 10:40:25",
"categories": [],
"tags": [],
"author": {
"id": 1,
"slug": "admin",
"name": "admin",
"first_name": "",
"last_name": "",
"nickname": "admin",
"url": "",
"description": ""
},
"comments": [],
"attachments": [],
"comment_count": 0,
"comment_status": "open"
}

所以基本上不是给我“状态”作为键,而“ok”作为一个值,我得到“s”作为一个对象,索引0对于json对象中的每个单个字符都有一个值“s”。 任何有关此事的帮助将不胜感激。

您需要在$ .ajax()请求中设置dataType:json ,以便jQuery将JSON格式的字符串转换为JavaScript对象,以便您进行处理。 您当前正在使用application/json ,它是一个mime类型,而不是jQuery请求中此字段的有效值。

在你的情况下,你甚至可以尝试data = eval(数据),这个javascript语句应该将你的字符串转换为json对象。

使用Jquery函数:

 data = $.parseJSON(data); 

在使用$ .each之前。

我在AngularJS应用程序中解决它的方法是将服务器(我使用Node Express)的响应作为JavaScript对象发送,而不是作为字符串。 没有别的东西适合我。

 var response = {}; response.error = "Error message"; res.send(response);