Home > Backend Development > PHP Tutorial > 关于淘宝API返回XML简单对象提取为数组的有关问题

关于淘宝API返回XML简单对象提取为数组的有关问题

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-13 12:13:54
Original
1108 people have browsed it

求助关于淘宝API返回XML简单对象提取为数组的问题?
一、通过淘宝API获得某个商品信息,得到如下XML对象
SimpleXMLElement Object ( [item] => SimpleXMLElement Object ( [auction_point] => 5 [detail_url] => http://item.taobao.com/item.htm?id=42234097497&spm=2014.23062087.0.0 [item_imgs] => SimpleXMLElement Object ( [@attributes] => Array ( [list] => true ) [item_img] => Array ( [0] => SimpleXMLElement Object ( [id] => 0 [position] => 0 [url] => http://img01.taobaocdn.com/bao/uploaded/i1/TB1gY_gGpXXXXX8apXXXXXXXXXX_!!0-item_pic.jpg ) [1] => SimpleXMLElement Object ( [id] => 17030079984 [position] => 1 [url] => http://img01.taobaocdn.com/bao/uploaded/i1/TB1.lKwGXXXXXXyapXXXXXXXXXX_!!0-item_pic.jpg ) [2] => SimpleXMLElement Object ( [id] => 17030079985 [position] => 2 [url] => http://img03.taobaocdn.com/bao/uploaded/i3/1703225540/TB25UT7aVXXXXXUXpXXXXXXXXXX_!!1703225540.jpg ) [3] => SimpleXMLElement Object ( [id] => 17030079986 [position] => 3 [url] => http://img02.taobaocdn.com/bao/uploaded/i2/1703225540/TB2.3r6aVXXXXX3XpXXXXXXXXXX_!!1703225540.jpg ) [4] => SimpleXMLElement Object ( [id] => 17030079987 [position] => 4 [url] => http://img01.taobaocdn.com/bao/uploaded/i1/1703225540/TB2dV__aVXXXXXlXpXXXXXXXXXX_!!1703225540.jpg ) ) ) [nick] => 雪荞旗舰店 [num_iid] => 42234097497 [price] => 88.00 [title] => 【买1送1】雪荞乌金红滇红茶叶礼云南凤庆特级密香功夫红茶包邮 ) ) Array ( [isError] => 1 [store_type] => SimpleXMLElement Object ( [0] => 5 ) [item_link] => SimpleXMLElement Object ( [0] => http://item.taobao.com/item.htm?id=42234097497&spm=2014.23062087.0.0 ) [img] => SimpleXMLElement Object ( [0] => http://img01.taobaocdn.com/bao/uploaded/i1/TB1gY_gGpXXXXX8apXXXXXXXXXX_!!0-item_pic.jpg ) [item_id] => SimpleXMLElement Object ( [0] => 42234097497 ) [item_title] => SimpleXMLElement Object ( [0] => 【买1送1】雪荞乌金红滇红茶叶礼云南凤庆特级密香功夫红茶包邮 ) [store_id] => SimpleXMLElement Object ( [0] => 雪荞旗舰店 ) [market_price] => SimpleXMLElement Object ( [0] => 88.00 ) ) 

二、赋值给$getdata

三、通过以下方法取值 
$result = array
(
'isError' =>true,
'store_type' =>$getdata->item->auction_point,
'item_link' =>$getdata->item->detail_url,
'img' =>$getdata->item->item_imgs->item_img[0]->url,
'item_id' =>$getdata->item->num_iid,
'item_title' =>$getdata->item->title,
'store_id' =>$getdata->item->nick,
'market_price' =>$getdata->item->price
);
为何得到的值是一个不正确的JSON对象
{"isError":true,"store_type":{"0":"5"},"item_link":{"0":"http:\/\/item.taobao.com\/item.htm?id=42234097497&spm=2014.23062087.0.0"},"img":{"0":"http:\/\/img01.taobaocdn.com\/bao\/uploaded\/i1\/TB1gY_gGpXXXXX8apXXXXXXXXXX_!!0-item_pic.jpg"},"item_id":{"0":"42234097497"},"item_title":{"0":"【买1送1】雪荞乌金红滇红茶叶礼云南凤庆特级密香功夫红茶包邮"},"store_id":{"0":"雪荞旗舰店"},"market_price":{"0":"88.00"}}

四、我想要得到的是
,"store_type":5,,而不是"store_type":{"0":"5"} 请大神帮忙为感!
------解决思路----------------------
echo $getdata->asXML();

不就得到了吗?

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template