Prestashop Web服务返回JSON

时间:2022-10-24 12:41:26

After extensive search over internet i am sure that Prestashop does not return data in JSON format, it only returns in XML format (which leads to cross domain accessing issue unfortunately).

在internet上广泛搜索之后,我确信Prestashop不会返回JSON格式的数据,它只返回XML格式(不幸的是,这导致跨域访问问题)。

Now, I am trying to convert XML(returned by Prestashop) to JSON. I want to write php code which could take XML from web service and sent back JSON. For this purpose i tried many tutorial but in vain. The converted JSON does not have value in it, so is useless. The methods i tried are listed below.

现在,我尝试将XML(由Prestashop返回)转换为JSON。我想编写php代码,它可以从web服务获取XML并将JSON返回。为了这个目的,我尝试了许多教程,但没有用。转换后的JSON中没有值,因此是无用的。下面列出了我尝试过的方法。

http://www.sitepoint.com/php-xml-to-json-proxy/
PHP convert XML to JSON

http://www.sitepoint.com/php-xml-to-json-proxy/ PHP将XML转换为JSON

XML to convert:

XML转换:

<name>
<language id="1" xlink:href="http://localhost/prestashop/api/languages/1">
<![CDATA[ iPod Nano ]]>
</language>
</name>

Returned JSON:

返回JSON:

"name":{"language":{"@attributes":{"id":"1"}}}

I hope for the help in this regard. Thank you.

我希望在这方面得到帮助。谢谢你!

2 个解决方案

#1


33  

I don't know about historical support for this, but...

我不知道历史支持这一点,但是……

In the latest version of Prestashop (currently v1.6.0.9), you can get a JSON response from any WebService API request by appending output_format=JSON to your request query string.

在最新版本的Prestashop(目前为v1.6.0.9)中,您可以通过将output_format=JSON添加到请求查询字符串中获得任何WebService API请求的JSON响应。

E.g. http://example.prestashop.com/api/products?output_format=JSON

例如,http://example.prestashop.com/api/products?output_format=JSON

#2


-2  

Prestashop has die(Tools::jsonEncode([Associative Array])) for ajax return or just remove die for non ajax return.

Prestashop有用于ajax返回的die(Tools::jsonEncode([Associative Array]))或用于非ajax返回的die。

#1


33  

I don't know about historical support for this, but...

我不知道历史支持这一点,但是……

In the latest version of Prestashop (currently v1.6.0.9), you can get a JSON response from any WebService API request by appending output_format=JSON to your request query string.

在最新版本的Prestashop(目前为v1.6.0.9)中,您可以通过将output_format=JSON添加到请求查询字符串中获得任何WebService API请求的JSON响应。

E.g. http://example.prestashop.com/api/products?output_format=JSON

例如,http://example.prestashop.com/api/products?output_format=JSON

#2


-2  

Prestashop has die(Tools::jsonEncode([Associative Array])) for ajax return or just remove die for non ajax return.

Prestashop有用于ajax返回的die(Tools::jsonEncode([Associative Array]))或用于非ajax返回的die。