PolymerJS POST JSON 格式化

PolymerJS POST JSON formatting

我正在尝试 POST 使用 PolymerJS ajax-forms,但我遇到了一个奇怪的 JSON 格式错误。有人能告诉我为什么按键周围的引号丢失了吗?我能想到的唯一解决方法是在键周围用引号手动构建正文。

代码片段: 我如何接收值(其余与更改的 ID 相同):

<div>
        <paper-input label="Title" id="course-title" floatingLabel value="{{item.title}}"></paper-input>
    </div>

 <access-core-ajax
              auto = "false"
              url="domain/courses"
              response="{{response}}"
              method="post"
              id="postCourse"
              contentType="application/json"
              headers='{"Accept": "application/json", "Content-Type":"application/json"}',
              body = "{{item}}">

            <template id="get-response-template" repeat="{{item in response.entries}}">
                    <p>Errors</p>
            </template>
        </access-core-ajax>

Polymer('create-new-course-page',{
        domReady: function() {
            console.log("Log: create-new-courses-page - Looks like we are domReady");
        },
        created: function() {
            console.log("Item initialized");
            this.item = {};
            this.data={};
        },
        createNewCourse: function(event) {
            console.log("HERE IS BODY", this.item);
            this.$.postCourse.go();


       }

并且 JSON 在日志中可见:

{ title: "WRU", // rest of key & values, where the keys are without the "" }

您需要先将正文转换为 JSON 字符串。 JSON.stringify 可以提供帮助。

...
createNewCourse: function(e) {
    this.$.postCourse.body = JSON.stringify(this.item);
    this.$.postCourse.go();
}

您可能需要在此处删除 body 属性。您还可以删除该自动属性,因为默认情况下它是假的。