Quantcast
Channel: JSON feeds context within Drupal 7 - Stack Overflow
Viewing all articles
Browse latest Browse all 3

JSON feeds context within Drupal 7

$
0
0

I'm trying to connect to a REST web service with Drupal 7. Data is supplied via a url and I want to pull it into the D7 site to create and populate nodes. I'm using the feeds module to map the content and the JSONPath parser as the parser. I have also included Feeds HTTPFetcher Append Headers module so that I can add custom headers in to make sure it is JSON being returned and not badly formatted xml which I was getting before.

Custom headers:

Accept|application/jsonContent-Type|application/json

I have a url that looks like http://192.136.0.31:8080/places/getAll

Further to the above I have the Devel module in place which is returning the feed array in the page using the code below in my template.php:

$request = drupal_http_request('http://192.136.0.31:8080/places/getAll', $options);dpm(drupal_json_decode($request->data));

This is what Devel returns:

... (Array, 1192 elements)   0 (Array, 17 elements)      Address1 (String, 19 characters ) 1-2 The Road name      Address2 (String, 9 characters ) Shuinnad

The problem I'm having is getting this into feeds and mapping to the relevant fields. I don't know what should go in the context field - I have tried $...*, $.*, $...[*] but no luck.

When I click on an Array element from the devel output it shows $...[0]['Address1'] which suggests that should be the context - no luck.

Quick Update - using the drupal_json_decode function I can split the array out how I need to using php

foreach ($json as $section => $items) {foreach ($items as $key => $value) {    //if ($key == 'Address1') {    echo "$section:\t$key\t:&nbsp;$value<br>";    //}    // check whether the current item is an array!    if(is_array($value)) {        echo "$key is sub array:<br />";        foreach($value as $subKey => $subValue)            echo "$subKey:\t$subValue<br />";    }}}

The question still stands, how do I replicate that in Feeds using the JSON parser?


Viewing all articles
Browse latest Browse all 3

Trending Articles