Pergunta

I have a big doubt about the JSON format the Services module (for Drupal 6) generates.

When I view the XML, all is OK.

<result is_array="true">
 <item>
  <nid>9</nid>
  <vid>9</vid>
  <type>producto</type>
 </item>
</result>

When I view the JSON, I see this:

[
 {
  "nid": "9",
  "vid": "9",
  "type": "producto",
 }
]

What I really is something like this:

[
 {
  "item":{
    "nid": "9",
    "vid": "9",
    "type": "producto",
  }
 }
]

How do I do this? Is there any configuration in the Services module that I can use to change the output, or do I need writing code?
I know the function to render JSON output.

Foi útil?

Solução

You should implement hook_services_request_postprocess_alter().

Outras dicas

As I mentioned before, hook_services_request_postprocess_alter will not provide you what type of data it's processing. It means that your code must be really hacky to catch exactly type of data you need.

You better create your own formatter with hook_rest_server_response_formatters_alter, and use it to render data.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a drupal.stackexchange
scroll top