Drupal 7 中的 JSON 提要上下文

标签 json rest drupal feed drupal-feeds

我正在尝试使用 Drupal 7 连接到 REST Web 服务。数据是通过 url 提供的,我想将其拉入 D7 站点以创建和填充节点。我正在使用提要模块来映射内容,并使用 JSONPath 解析器作为解析器。我还包含了 Feeds HTTPFetcher Append Headers 模块,这样我就可以添加自定义 header ,以确保返回的是 JSON 而不是我之前得到的格式错误的 xml。

自定义 header :

Accept|application/json
Content-Type|application/json

我有一个看起来像 http://192.136.0.31:8080/places/getAll

的 url

除上述之外,我还有 Devel 模块,它使用我的 template.php 中的以下代码返回页面中的提要数组:

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

这是 Devel 返回的内容:

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

我遇到的问题是将其放入提要并映射到相关字段。我不知道上下文字段中应该放什么 - 我试过 $...*$.*、$...[*] 但没有成功.

当我从 devel 输出中单击数组元素时,它显示 $...[0]['Address1'] 这表明应该是上下文 - 运气不好。

快速更新 - 使用 drupal_json_decode 函数我可以将数组拆分为我需要使用 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 />";
    }
}
}

问题仍然存在,我如何使用 JSON 解析器在 Feeds 中复制它?

最佳答案

您可能需要尝试这个模块:Feeds JSONPath Parser

关于Drupal 7 中的 JSON 提要上下文,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23628404/

相关文章:

drupal - 如何从特定的 Drupal 网络表单中删除提交按钮

image - Drupal 7 : grayscale image to colored at mouse-hover. 使用 ImageStyles 生成的图像

java - JSONObject getstring 从字符串中删除零

c# - 在 C# .NET 中通过服务帐户而不是个人帐户进行身份验证以使用 Google 表格

python - 从 Foursquare API 解析嵌套的 JSON

asp.net-mvc - ASP.NET MVC 从服务器端调用 REST 服务

java - 从 Android 应用程序自动在本地网络上查找服务器

javascript - 将 html 表单输入保存到 json 文件

python - 在 Django View 中接收 JSON 输入的最佳实践是什么?

css - Drupal:CSS 中区域背景图像的无效属性值