Drupal 7中的JSON Feed上下文 [英] JSON feeds context within Drupal 7
问题描述
我正在尝试使用Drupal 7连接到REST Web服务。数据通过URL提供,我想将其拉入D7站点以创建和填充节点。我正在使用feed模块将内容和JSONPath解析器映射为解析器。我还包括Feed HTTPFetcher Append Headers模块,以便我可以添加自定义标题,以确保它是返回的JSON,而不是格式不正确的xml,我以前得到。
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.
自定义标题:
Accept|application/json
Content-Type|application/json
我有一个url,看起来像 http://192.136.0.31:8080/places/getAll
I have a url that looks like http://192.136.0.31:8080/places/getAll
除了上面我有一个Devel模块到位,它是使用我的template.php中的代码返回页面中的feed数组:
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));
这是Devel返回的:
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
我遇到的问题是将其转换为Feed和映射到相关领域。我不知道在上下文领域应该走什么 - 我试过 $ ... *
, $。*
,$ ... [*]但没有运气。
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.
当我从devel输出点击Array元素时,会显示$ ... [0] ['Address1'],这表明应该是上下文 - 没有运气
When I click on an Array element from the devel output it shows $...[0]['Address1'] which suggests that should be the context - no luck.
快速更新 - 使用drupal_json_decode函数我可以拆分数组,我需要如何使用php
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: $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 />";
}
}
}
问题依然如何我使用JSON解析器在Feed中复制这个?
The question still stands, how do I replicate that in Feeds using the JSON parser?
推荐答案
请参阅本教程
上下文:将JSONPath表达式放在表示数据的数组的路径上。例如,在我的文件中,这将是$ .albums.data。*。如果这是一个PHP数组,那将基本上是
Context: is where you put the JSONPath expression that represents the path to the array representing your data. For instance, in my file, this would be $.albums.data.*. If this were a PHP array, that would be basically
foreach($ facebook ['albums'] ['data'] as $价值);
foreach($facebook['albums']['data'] as $value);
- See more at: http://glassdimly.com/blog/tech/drupal-7-feeds-extensible-parsers-jsonpath-map-json-fields/feeds-extensible-parsers#sthash.BrIutjfl.dpuf
这篇关于Drupal 7中的JSON Feed上下文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!