问题描述
我正在使用GuzzleHttp客户端来获取xml 这是API URL:http://search.sep.gob.mx/solr/cedulasCore/select?fl=%2A%2Cscore&q=1629426&start=0&rows=100&facet=true&indent=on
有什么方法可以显示来自xml的视图,还是必须将其转换为json格式?
这是api中的xml
<response>
<lst name="responseHeader">
<int name="status">0</int>
<int name="QTime">1</int>
<lst name="params">
<str name="facet">true</str>
<str name="fl">*,score</str>
<str name="indent">on</str>
<str name="start">0</str>
<str name="q">1629426</str>
<str name="rows">100</str>
</lst>
</lst>
<result name="response" numFound="1" start="0" maxScore="5.1923494">
<doc>
<str name="nombre">ENRIQUE</str>
<str name="id">1629426|C1</str>
<str name="numCedula">1629426</str>
<str name="titulo">LICENCIATURA EN DERECHO</str>
<str name="genero">1</str>
<str name="institucion">UNIVERSIDAD PANAMERICANA</str>
<str name="materno">NIETO</str>
<int name="anioRegistro">1991</int>
<str name="tipo">C1</str>
<str name="paterno">PEÑA</str>
<date name="timestamp">2020-09-04T06:14:46.539Z</date>
<float name="score">5.1923494</float>
</doc>
</result>
<lst name="facet_counts">
<lst name="facet_queries"/>
<lst name="facet_fields"/>
<lst name="facet_dates"/>
<lst name="facet_ranges"/>
</lst>
</response>
这是我的控制人
public function validacion(Request $request)
{
$numCedula = $request->get('buscar');
$client = new Client([
'base_uri' => 'http://search.sep.gob.mx','timeout' => 300,'Content-Type: application/vnd.api+json','Accept: application/vnd.api+json'
]);
$response = $client->request('GET',"http://search.sep.gob.mx/solr/cedulasCore/select?fl=%2A%2Cscore&q=10390826&start=0&rows=100&facet=true&indent=on");
$api =$response->getBody()->getContents();
return view('vali',compact('api'));
}
这是我的观点
@foreach($api['response']['doc'] as $cedu)
<h1>Num cedu:{{$cedu['numCedula']}}</h1>
<h1>name: {{$cedu['nombre']}}</h1>
@endforeach
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)