jeudi 10 mai 2018

How to convert the json data to the below mentioned format

The data given below is the josn converted from xml data.

{"tldlist":{"tld":[{"tld":"co.uk"},{"tld":"eu"},{"tld":"live"},{"tld":{}}],"tldcount":"4"},"Command":"GETTLDLIST","APIType":"API","Language":"eng","ErrCount":"0","ResponseCount":"0","MinPeriod":{},"MaxPeriod":"10","Server":"SJL1VWRESELL_T","Site":"eNom","IsLockable":{},"IsRealTimeTLD":{},"TimeDifference":"+0.00","ExecTime":"0.000","Done":"true","TrackingKey":"b3c16684-c533-4947-b40a-19a5b4c08a31","RequestDateTime":"5\/10\/2018 12:54:28 AM","debug":{}}

I need to convert the above data to the format mentioned below:

  array (
 'tldlist' => 
array (
'tld' => 
array (
  0 => 
  array (
    'tld' => 'co.uk',
  ),
  1 => 
  array (
    'tld' => 'eu',
  ),
  2 => 
  array (
    'tld' => 'live',
  ),
  3 => 
  array (
    'tld' => 
    array (
    ),
  ),
),
'tldcount' => '4',
),
'Command' => 'GETTLDLIST',
'APIType' => 'API',
'Language' => 'eng',
'ErrCount' => '0',
'ResponseCount' => '0',
'MinPeriod' => 
 array (
),
 'MaxPeriod' => '10',
 'Server' => 'SJL1VWRESELL_T',
 'Site' => 'eNom',
 'IsLockable' => 
 array (
 ),
  'IsRealTimeTLD' => 
   array (
   ),
  'TimeDifference' => '+0.00',
  'ExecTime' => '0.000',
  'Done' => 'true',
  'TrackingKey' => 'b3c16684-c533-4947-b40a-19a5b4c08a31',
  'RequestDateTime' => '5/10/2018 12:54:28 AM',
  'debug' => 
   array (
   ),
 )

Find my controller code:

  public function test(){

    $response = file_get_contents('https://resellertest.enom.com/interface.asp?command=gettldlist&uid=resellid&pw=resellpw&responsetype=xml');       

        $data = simplexml_load_string($response);
        $configdata   = json_encode($data);

        return view('clientlayout.main.test1', array('configdata' => 
       $configdata ));


      }

Suggest me solution to get the data in the mentioned format.I need the json data in the decoded format in my view.when I use json_decode in the controller I'm getting error as "htmlspecialchars() expects parameter 1 to be string, array given".



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2K62Kao
via IFTTT

Aucun commentaire:

Enregistrer un commentaire