无标题JSON响应

无标题JSON响应,json,api,parsing,Json,Api,Parsing,我正在编写一个API,从中访问圣经段落,JSON响应返回时没有“response”头或任何层次结构名称。Firebug显示我的GET请求返回为200状态,但响应选项卡始终为空。如果我直接在浏览器中键入url,我会得到想要的结果,但我不知道如何处理JSON这样的内容。示例: 这就是JSON的样子 [ { "bookname": "Luke", "chapter": "9", "verse": "1", "text": "<t

我正在编写一个API,从中访问圣经段落,JSON响应返回时没有“response”头或任何层次结构名称。Firebug显示我的GET请求返回为200状态,但响应选项卡始终为空。如果我直接在浏览器中键入url,我会得到想要的结果,但我不知道如何处理JSON这样的内容。示例:

这就是JSON的样子

[
    {
      "bookname": "Luke",
        "chapter": "9",
        "verse": "1",
        "text": "<t /><p class=\"bodytext\">After<n id=\"1\" /> Jesus<n id=\"2\" /> called<n id=\"3\" /> the twelve<n id=\"4\" /> together, he gave them power and authority over all demons and to cure<n id=\"5\" /> diseases,",
        "title": "The Sending of the Twelve Apostles"
    },
    {
      "bookname": "Luke",
        "chapter": "9",
        "verse": "2",
        "text": "and he sent<n id=\"1\" /> them out to proclaim<n id=\"2\" /> the kingdom of God<n id=\"3\" /> and to heal the sick.<n id=\"4\" />"
    },
    {
        "bookname": "Luke",
        "chapter": "9",
        "verse": "3",
        "text": "He<n id=\"1\" /> said to them, “Take nothing for your<n id=\"2\" /> journey &#8211; no staff,<n id=\"3\" /> no bag,<n id=\"4\" /> no bread, no money, and do not take an extra tunic.<n id=\"5\" />"
    },
    {
        "bookname": "Luke",
        "chapter": "9",
        "verse": "4",
        "text": "Whatever<n id=\"1\" /> house you enter, stay there<n id=\"2\" /> until you leave the area.<n id=\"3\" />"
    },
    {
        "bookname": "Luke",
        "chapter": "9",
        "verse": "5",
        "text": "Wherever<n id=\"1\" /> they do not receive you,<n id=\"2\" /> as you leave that town,<n id=\"3\" /> shake the dust off<n id=\"4\" /> your feet as a testimony against them.”"
    },
    {
        "bookname": "Luke",
        "chapter": "9",
        "verse": "6",
        "text": "Then<n id=\"1\" /> they departed and went throughout<n id=\"2\" /> the villages, proclaiming the good news<n id=\"3\" /> and healing people everywhere.</p>"
    },
    {
        "bookname": "Luke",
        "chapter": "9",
        "verse": "7",
        "text": "<t /><p class=\"bodytext\">Now Herod<n id=\"1\" /> the tetrarch<n id=\"2\" /> heard about everything that was happening, and he was thoroughly perplexed,<n id=\"3\" /> because some people were saying that John<n id=\"4\" /> had been raised from the dead,",
        "title": "Herod&#8217;s Confusion about Jesus"
    },
   (...)
]

如果您尝试使用不同的JSON URL,比如:
http://labs.bible.org/api/?passage=luke+9:3&type=json&callback=?
(删除
&formatting=full
并在末尾添加
&callback=?

如果您得到的响应没有格式化标记(所有的
标记),那么它似乎对我来说是解析的,至少在JSFIDLE上的这个示例中是这样的:

更新:以下是一个示例,说明如何使用jQuery从URL获取JSON:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script>
$(function() {
    var json_url = "http://labs.bible.org/api/?passage=luke+9:3&type=json&callback=?";

    $.getJSON(json_url, function(json_response) { 
        for(var i = 0; i < json_response.length; i++) {
            alert(json_response[i].text);
        }
    });
});
</script>

$(函数(){
var json_url=”http://labs.bible.org/api/?passage=luke+9:3&type=json&callback=?”;
$.getJSON(json_url,函数(json_响应){
对于(var i=0;i
基本上,该代码:

  • 包括
  • 将JavaScript放入
    ready
    函数(…)
  • 确保调用包含()
  • 调用jQuery的
    $.getJSON()
    函数(该函数使用API URL并返回名为
    json\u response
    )的响应)
  • 循环通过
    json\u响应
    ,并允许您获得所需的任何值。(您可能希望在某个时候取消
    alert()
    函数…;)

  • 大多数语言都有一个JSON解析器,可以帮助您访问JSON元素。你用什么语言?对于java,有GSON;对于Python和JavaScript,有内置的json支持;对于Objective-C,有JSONKit;对于Perl,有json包。。。这个API是用某种编程语言编写的吗?我是用JavaScript编写的。我知道它有一个JSON.parse()方法,但我总是在JSON的顶部看到“response”,所以我会访问不同的信息,比如(数据是responseText)“data.response.bookname”,如果有多个结果,那么我会设置一个循环以通过它们递增。我只是不知道我会怎么做。你发布的代码基本上就是我要做的。当然,不是一行接一行,而是同一个概念。我想真正的问题是,对HTTP GET的响应返回为空白。我将发布我的函数来检索和分析数据。@Jaylinfredrick感谢发布这些函数;只是想知道,但是。。。(在项目的参数范围内)是否可以使用jQuery而不是手工编写“GetJSON”部分?是的,这是完全可能的,但问题是我对jQuery不太熟悉。我仍在努力了解它。@Jaylinfredrick我已经更新了前面的答案,希望能把它带到一个更好的地方:)非常感谢您抽出时间。你帮了我大忙。
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
    <script>
    $(function() {
        var json_url = "http://labs.bible.org/api/?passage=luke+9:3&type=json&callback=?";
    
        $.getJSON(json_url, function(json_response) { 
            for(var i = 0; i < json_response.length; i++) {
                alert(json_response[i].text);
            }
        });
    });
    </script>