你在这里

关于REST_Server中create node时taxonomy_term和entity_reference的json结构的问题

主标签

REST 上传字段dpm出来的结构

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

zi_duan_jie_gou_.png

接下来我在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 DATE USER LOCATION REFERRER MESSAGE SEVERITY HOSTNAME

OPERATIONS

form
Sunday, September 25, 2016 - 21:33
EwenDeng
http://www.tsghy.com.cn/services/node
 
Illegal choice in 条码分类 element.
error
192.168.10.204
TYPE DATE USER LOCATION REFERRER MESSAGE SEVERITY HOSTNAME
php
Sunday, September 25, 2016 - 21:47
EwenDeng
http://www.tsghy.com.cn/services/node
 
Warning: Illegal offset type in taxonomy_field_validate() (line 1530 of /usr/websit/www/modules/taxonomy/taxonomy.module).
warning
192.168.10.204

 

问下看看谁知道在REST时的taxonomy_term的json要如何组织。

Drupal 版本: 

猜你喜欢

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