0
votes

I have drupal 7 deployment with services 3 module. I have Services with JSON output configured. When I get my results, the custom fields return labels instead of the actual field names. For example, Node Title which is built in shows node_title. However, 1 Year a custom field that was stored as field_1_year shows up as 1 Year. This makes it difficult to parse JSON. Any suggestions?

1
I'm always using my custom made feeds. A little more work, but full output control.MilanG
@MilanG - thanks. Do you have a sample code posted somewhere?techwestcoastsfosea

1 Answers

1
votes

You can make your custom json feed i.e.:

  • Make you php script and at top add standard D7 bootstrap:

    define('DRUPAL_ROOT', getcwd());

    require_once DRUPAL_ROOT . '/includes/bootstrap.inc'; drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);

After this code you'll have all Drupal's functionalities available in your script.

  • Add your code to get values you want. You can use Drupal's database api, or even easier, create some view and use views_get_view_result() function to get values view returns:

https://api.drupal.org/api/views/views.module/function/views_get_view_result/7

  • Then iterate trough your results and create another php array containing values you want in the way you want.

  • Use json_encode to convert your array to json string: http://php.net/manual/en/function.json-encode.php

  • Print out your json string. You can even print out json header before it, so apps that are getting feed will know it's json (sometime may be needed)

    header('Content-Type: application/json');

Something like that...