node的Data结构如上图,其中field_sample_state是一个taxonomy_term,field_sampletracert 是一个node reference。按着一般情况,直接生成了以下的Json:
'field_smaple_state':{ 'und':[{'tid':'560'}]},
'field_sampletracert':{'und':[{'target_id':'98533'}]},
但实际post到服务器的时侯,Service不能识别它的结构,造成上传失败,经过网络搜索和多次测试和读文章,发现它的结构与新建字段时的设置有关,并找到下面一句描述:
I found the solution! The required data structure depends on the input widget, since Services uses the form submit handlers (which may be a major design flaw). For "Autocomplete/Tagging" the label (id)
thingy is necessary. But if you switch to checkboxes it reads "field_reference": { 1:1, 2:2, ... ,nid:nid}
and for select box "field_reference": [1,2,3 ... nid]
.
The REST-API depends on the widgets the frontend uses ... but at least it works. I guess its upside is that REST-posts are validated just as normal form inputs are. I'll also have a look at the approach implemented http://drupal.org/project/restws
对此,需要对设置改为select list并将json修改为:
'field_smaple_state':{'und':['560']},
'field_sampletracert':{'und':'129328'},
经过测试,得到post的正确结果。