对于可读的补丁方法,我的Drupal站点需要这样:
{
"_links":
{"type":{"href":"http://drupal.dd:8083/rest/type/node/task"}},
"nid":{"":5},
"title":{"value":"Change"},
"body":{"":"i dont know why?"}
}
到目前为止我所做的是:
{
"_links":
[{"type":{"href":"http://drupal.dd:8083/rest/type/node/task"}}],
"nid":[{"":5}],
"title":[{"value":"Change"}],
"body":[{"":"i dont know why?"}]
}
它到处都有括号......
在我的角度应用程序中,我从表单获取所有数据,并发送到此函数以创建Web服务的数据:
save(name: string, body:string): void {
let task: any = {
_links: [],
nid: [],
title: [],
body: []
};
const id = +this.route.snapshot.paramMap.get('id')
task.nid.push({"": id});
task._links.push({type: {"href": "http://drupal.dd:8083/rest/type/node/task"} });
task.title.push({value: name});
task.body.push({ "": body});
console.log(JSON.stringify(task));
}
所以我的问题是,如何从对象中删除括号?
@Llai是对的,我不需要一个数组:
let task: any = {
_links: null,
nid: null,
title: null,
body: null
};
const id = +this.route.snapshot.paramMap.get('id')
task.nid = {"": id};
task._links = {type: {"href": "http://drupal.dd:8083/rest/type/node/task"} };
task.title = {value: name};
task.body = { "": body};