【问题标题】:Google Cloud Endpoint no result via JavaScript ClientGoogle Cloud Endpoint 通过 JavaScript 客户端没有结果
【发布时间】:2013-06-15 15:59:27
【问题描述】:

我正在托管一个 GAE 应用程序并尝试让 Google Cloud Endpoints 工作。现在一切都已设置好并使用 curl 进行了测试:

curl http://localhost:8888/_ah/api/myendpoint/v1/queryData

只返回 1 个正确的项目:

{
  "items" : [ {
    "id" : "220",
    "timestamp" : "1371475009682951",
    "identifier" : "test1.0",
    "value" : "523"
  } ]
}

通过我的 JavaScript 客户端的相同调用无缘无故返回:

gapi.client.myendpoint.queryData().execute( function(result) {
        console.log("result: " + result);
});

我得到的输出是:

result: [object Object]

我错过了什么? 感谢您的帮助。

【问题讨论】:

    标签: javascript google-app-engine google-api google-cloud-endpoints


    【解决方案1】:

    result 已经是 JSON 对象,而不是字符串。

    使用"result: " + result 可以强制将对象转换为字符串,而[object Object] 正是默认的显示方式。

    例如console.log("result: " + {"name": "I'm an object!"}) 会给你完全相同的输出

    改用console.log(result),您应该会看到响应的真实内容。

    【讨论】:

    • 非常感谢。刚回到我的问题上,准确地评论一下,因为我刚刚意识到自己。一定是这里的温度让我失明。 :)
    猜你喜欢
    • 1970-01-01
    • 2016-07-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-23
    • 2014-05-14
    相关资源
    最近更新 更多