请先看我的term_reference和entity_reference字段在drupal中的结构:

接下来我在C#中组织的Json结构如下:
private string create_barcode_str = @"{'title':'1474341254Vq','log':'Created by Ewen Sample Scanner V1.0','status':'1','comment':'1','promote':'0',
'sticky':'0','type':'barcodeexchange','language':'und','created':'1474342113','changed':'1474342113','translate':'0',
'field_smaple_state':{ 'und':[{'tid':'560'}]},
'field_barcode_code':{'und':[{'value':'B00098533001'}]},
'field_sampletracert':{'und':[{'target_id':'98533'}]},
'field_sacndate':{'und':[{'value':'1474341278','timezone':'Asia/Shanghai','timezone_db':'UTC','date_type':'datestamp'}]},
'field_tracerttag':{'und':[{'value':'0'}]},
'field_printtag':{'und':[{'value':'1'}]},
'field_barcodetype':{'und':[{'tid':'593'}]},
}";
跟着是post到Drupal中的Log的记录到的数据结构:
Passed arguments:
Array
(
[0] => Array
(
[title] => title_131192835267385294
[log] => Created by Ewen Sample Scanner V1.0
[status] => 1
[comment] => 1
[promote] => 0
[sticky] => 0
[type] => barcodeexchange
[language] => und
[created] => 2016-09-25T21:25:28.1054608Z
[changed] => 2016-09-25T21:25:28.1059697Z
[translate] => 0
[field_barcode_code] => Array
(
[und] => Array
(
[0] => Array
(
[value] => B00082042002
)
)
)
[field_sampletracert] => Array
(
[und] => Array
(
[0] => Array
(
[target_id] => 98533
)
)
)
[field_sacndate] => Array
(
[und] => Array
(
[0] => Array
(
[value] => 2016/9/25 21:25:26
[timezone] => Asia/Shanghai
[timezone_db] => UTC
[date_type] => datestamp
)
)
)
[field_tracerttag] => Array
(
[und] => Array
(
[0] => Array
(
[value] => 0
)
)
)
[field_printtag] => Array
(
[und] => Array
(
[0] => Array
(
[value] => 1
)
)
)
)
)
之后就是Drupal给出了个报错信息:
第一条是说这个term错误的:
| TYPE | form |
|---|---|
| DATE | Sunday, September 25, 2016 - 21:33 |
| USER | EwenDeng |
| LOCATION | http://www.tsghy.com.cn/services/node |
| REFERRER | |
| MESSAGE | Illegal choice in 条码分类 element. |
| SEVERITY | error |
| HOSTNAME | 192.168.10.204 |
|
OPERATIONS |
| TYPE | php |
|---|---|
| DATE | Sunday, September 25, 2016 - 21:47 |
| USER | EwenDeng |
| LOCATION | http://www.tsghy.com.cn/services/node |
| REFERRER | |
| MESSAGE | Warning: Illegal offset type in taxonomy_field_validate() (line 1530 of /usr/websit/www/modules/taxonomy/taxonomy.module). |
| SEVERITY | warning |
| HOSTNAME | 192.168.10.204 |
问下看看谁知道在REST时的taxonomy_term的json要如何组织。
板块
Drupal 版本
I found the solution! The
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