如何将下面提到的 xml 数据转换为 laravel 中的 json 数组
How to convert the below mentioned xml data into json array in laravel
在 xml 数据下方查找:
<?xml version="1.0" encoding="utf-8"?> <interface-response> <Command>CHECK</Command> <APIType>API.NET</APIType> <Language>eng</Language> <ErrCount>1</ErrCount> <errors> <Err1>User not permitted from this IP address - 113.193.131.41. See http://enom.help/whitelist for details</Err1> </errors> <ResponseCount>1</ResponseCount> <responses> <response> <ResponseNumber>713254</ResponseNumber> <ResponseString>Policy error; unauthorized; user(s)</ResponseString> </response> </responses> <MinPeriod>1</MinPeriod> <MaxPeriod>10</MaxPeriod> <Server>sjl0vwapi08</Server> <Site>eNom</Site> <IsLockable>True</IsLockable> <IsRealTimeTLD>True</IsRealTimeTLD> <TimeDifference>+7.00</TimeDifference> <ExecTime>0.034</ExecTime> <Done>true</Done> <TrackingKey>5baa515b-8e29-4517-b879-05ae68e94f9a</TrackingKey> <RequestDateTime>5/9/2018 3:49:10 AM</RequestDateTime> <debug/> </interface-response>
我需要将上面的xml数据转换成json数组,并传递给控制器查看。
在下面找到控制器代码:
public function test()
{
$response = Curl::to('https://reseller.enom.com/interface.asp?command=check&sld=decksys&tld=info&responsetype=xml&uid=userid&pw=password')->get();
$data = simplexml_load_string($response);
$configdata = json_encode($data);
$value = json_decode($configdata, true);
return view('clientlayout.main.test', array('response' =>$response));
}
在下面找到查看代码:
{{$response}}
路线如下:
Route::get('/test','EnomController@test');
提出一个解决方案解决这个问题并在我的视图页面中打印数据。
只需执行以下操作即可。
public function test()
{
$response = file_get_contents('your_xml_url');
$data = simplexml_load_string($response);
$configdata = json_encode($data);
return view('clientlayout.main.test', array('response' => $configdata ));
}
在 xml 数据下方查找:
<?xml version="1.0" encoding="utf-8"?> <interface-response> <Command>CHECK</Command> <APIType>API.NET</APIType> <Language>eng</Language> <ErrCount>1</ErrCount> <errors> <Err1>User not permitted from this IP address - 113.193.131.41. See http://enom.help/whitelist for details</Err1> </errors> <ResponseCount>1</ResponseCount> <responses> <response> <ResponseNumber>713254</ResponseNumber> <ResponseString>Policy error; unauthorized; user(s)</ResponseString> </response> </responses> <MinPeriod>1</MinPeriod> <MaxPeriod>10</MaxPeriod> <Server>sjl0vwapi08</Server> <Site>eNom</Site> <IsLockable>True</IsLockable> <IsRealTimeTLD>True</IsRealTimeTLD> <TimeDifference>+7.00</TimeDifference> <ExecTime>0.034</ExecTime> <Done>true</Done> <TrackingKey>5baa515b-8e29-4517-b879-05ae68e94f9a</TrackingKey> <RequestDateTime>5/9/2018 3:49:10 AM</RequestDateTime> <debug/> </interface-response>
我需要将上面的xml数据转换成json数组,并传递给控制器查看。
在下面找到控制器代码:
public function test()
{
$response = Curl::to('https://reseller.enom.com/interface.asp?command=check&sld=decksys&tld=info&responsetype=xml&uid=userid&pw=password')->get();
$data = simplexml_load_string($response);
$configdata = json_encode($data);
$value = json_decode($configdata, true);
return view('clientlayout.main.test', array('response' =>$response));
}
在下面找到查看代码:
{{$response}}
路线如下:
Route::get('/test','EnomController@test');
提出一个解决方案解决这个问题并在我的视图页面中打印数据。
只需执行以下操作即可。
public function test()
{
$response = file_get_contents('your_xml_url');
$data = simplexml_load_string($response);
$configdata = json_encode($data);
return view('clientlayout.main.test', array('response' => $configdata ));
}