改变Drupal中的Json输出

时间:2016-03-20 12:56:26

标签: drupal drupal-7 drupal-6 drupal-modules drupal-views

我从一个看起来像这样的视图中输出一个json文档:

[
    {
        "NewsTitle": "asdas",
        "ItemDescription": "asdasdasd\r\n",
        "NumofViews": "3",
        "Likes": "0",
        "PostDate": "10 Mar, 2016",
        "ImageUrl": "6_n_0.jpg",
        "NewsType": "8",
        "ShareURL": "",
        "VideoURL": "https://www.youtube.com/",

    }
]

我想删除开头的括号,以此格式输出:

{
"menu": {
        "NewsTitle": "asdas",
        "ItemDescription": "asdasdasd\r\n",
        "NumofViews": "3",
        "Likes": "0",
        "PostDate": "10 Mar, 2016",
        "ImageUrl": "6_n_0.jpg",
        "NewsType": "8",
        "ShareURL": "",
        "VideoURL": "https://www.youtube.com/",

    }
}

这是我正在使用的配置: 在视图中: 格式 格式:JSON数据文档|设置 FIELDS 格式:JSON数据文档|设置

Root object name
 *empty*
The name of the root object in the JSON document. e.g nodes or users or forum_posts
Top-level child object
*empty*
The name of each top-level child object in the JSON document. e.g node or user or forum_post
Field output
 Normal *chosen*
 Raw
For each row in the view, fields can be output as either the field rendered by Views, or by the raw content of the field.
 Plaintext output *selected*
For each row in the view, strip all markup from the field output.
 Remove newlines
Strip newline characters from the field output.
JSON data format
 Simple *selected*
 MIT Simile/Exhibit
 To be consumed by jqGrid
What object format will be used for JSON output.
JSONP prefix

If used the JSON output will be enclosed with parentheses and prefixed by this label, as in the JSONP format.
Content-Type
 Default: application/json *selected*
 text/json
 application/javascript
The Content-Type header that will be sent with the JSON output.
 Views API mode
With Views API mode the JSON will embedded as normal content so normal page processing is used. Leave it unchecked when JSON should be printed directly to the client.
 Object arrays
Outputs an object rather than an array when a non-associative array is used. Especially useful when the recipient of the output is expecting an object and the array is empty.
 Numeric strings
Encodes numeric strings as numbers.
 Numeric strings *selected*
Encodes large integers as their original string value.
 Pretty print *selected*
Use whitespace in returned data to format it.
 Unescaped slashes *selected*
Don't escape forward slashes /.
 Unescaped unicode
Encode multibyte Unicode characters literally (default is to escape as \uXXXX).

0 个答案:

没有答案