通过使用卷曲来获取JSON的索引值,然后用其他值更改值(替换)。我无法获得索引值,以便我可以替换

发布于 2025-02-13 22:33:15 字数 1387 浏览 0 评论 0原文

我正在Drupal中使用WebForm,并尝试通过使用自定义模块中的curl操作将REST API生成的默认json转换为自定义JSON,以更改一些关键值,例如标签等标题等...

没有得到如何获得的方式要做?任何身体都可以在这里提供帮助吗?

<?php
 
namespace Drupal\custom_rest_services\Controller;


use Symfony\Component\HttpFoundation\JsonResponse;


class custom_rest_servicesController {
  public function converter_json_formio() { 
    
    

    return new jsonresponse( [

      'data' => $this->getResult(),
      'method' => 'GET',

    ]
    );
  }
  
  private function getResult(){
    

    $curl = curl_init();
    
    curl_setopt_array($curl, array(
      CURLOPT_URL => 'http://localhost/install-dir/web/webform_rest/feedback_13/fields',
      CURLOPT_RETURNTRANSFER => true,
      CURLOPT_ENCODING => '',
      CURLOPT_MAXREDIRS => 10,
      CURLOPT_TIMEOUT => 0,
      CURLOPT_FOLLOWLOCATION => true,
      CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
      CURLOPT_CUSTOMREQUEST => 'GET',
      CURLOPT_HTTPHEADER => array(
        'Authorization: Basic YWRtaW46QWRtaW5AMTIz'
      ),
    ));
    
    $result = curl_exec($curl);

    if (curl_errno($ch)) { echo curl_error($ch); }
 
   
    else {
      
      $decoded = json_decode($result);
      print_r($decoded); // ARRAY
    }
curl_close($curl);

// return  $result;
  }

}

am using webform in drupal and trying to convert json which is default generated by the rest api to custom json by using the curl operation in custom module, to change the some key value like title with label and so on...

am not getting how to do? can any body help here..

<?php
 
namespace Drupal\custom_rest_services\Controller;


use Symfony\Component\HttpFoundation\JsonResponse;


class custom_rest_servicesController {
  public function converter_json_formio() { 
    
    

    return new jsonresponse( [

      'data' => $this->getResult(),
      'method' => 'GET',

    ]
    );
  }
  
  private function getResult(){
    

    $curl = curl_init();
    
    curl_setopt_array($curl, array(
      CURLOPT_URL => 'http://localhost/install-dir/web/webform_rest/feedback_13/fields',
      CURLOPT_RETURNTRANSFER => true,
      CURLOPT_ENCODING => '',
      CURLOPT_MAXREDIRS => 10,
      CURLOPT_TIMEOUT => 0,
      CURLOPT_FOLLOWLOCATION => true,
      CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
      CURLOPT_CUSTOMREQUEST => 'GET',
      CURLOPT_HTTPHEADER => array(
        'Authorization: Basic YWRtaW46QWRtaW5AMTIz'
      ),
    ));
    
    $result = curl_exec($curl);

    if (curl_errno($ch)) { echo curl_error($ch); }
 
   
    else {
      
      $decoded = json_decode($result);
      print_r($decoded); // ARRAY
    }
curl_close($curl);

// return  $result;
  }

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文