0

我发出了一个 twitter api 请求(GET 趋势/位置 API),结果是这样的:

[{"trends":[{"name":"#BabyIsStaying","url":"http:\/\/twitter.com\/search?q=%23BabyIsStaying","promoted_content":null,"query":"%23BabyIsStaying","events":null},{"name":"#AkTakipBa\u015fl\u0131yor","url":"http:\/\/twitter.com\/search?q=%23AkTakipBa%C5%9Fl%C4%B1yor","promoted_content":null,"query":"%23AkTakipBa%C5%9Fl%C4%B1yor","events":null},{"name":"#\u00c7apulcuTakip","url":"http:\/\/twitter.com\/search?q=%23%C3%87apulcuTakip","promoted_content":null,"query":"%23%C3%87apulcuTakip","events":null},{"name":"#SadeceKar\u015f\u0131l\u0131kl\u0131Takiple\u015fme","url":"http:\/\/twitter.com\/search?q=%23SadeceKar%C5%9F%C4%B1l%C4%B1kl%C4%B1Takiple%C5%9Fme","promoted_content":null,"query":"%23SadeceKar%C5%9F%C4%B1l%C4%B1kl%C4%B1Takiple%C5%9Fme","events":null},{"name":"#soysuzek\u015fis\u00f6zl\u00fck","url":"http:\/\/twitter.com\/search?q=%23soysuzek%C5%9Fis%C3%B6zl%C3%BCk","promoted_content":null,"query":"%23soysuzek%C5%9Fis%C3%B6zl%C3%BCk","events":null},{"name":"B\u00fcy\u00fck FENERBAH\u00c7E Taraftarlar\u0131Takiple\u015fiyor","url":"http:\/\/twitter.com\/search?q=%22B%C3%BCy%C3%BCk+FENERBAH%C3%87E+Taraftarlar%C4%B1Takiple%C5%9Fiyor%22","promoted_content":null,"query":"%22B%C3%BCy%C3%BCk+FENERBAH%C3%87E+Taraftarlar%C4%B1Takiple%C5%9Fiyor%22","events":null},{"name":"Sar\u0131K\u0131rm\u0131z\u0131Aile UnfollowsuzTakiple\u015fiyor","url":"http:\/\/twitter.com\/search?q=%22Sar%C4%B1K%C4%B1rm%C4%B1z%C4%B1Aile+UnfollowsuzTakiple%C5%9Fiyor%22","promoted_content":null,"query":"%22Sar%C4%B1K%C4%B1rm%C4%B1z%C4%B1Aile+UnfollowsuzTakiple%C5%9Fiyor%22","events":null},{"name":"D\u00fcnyadaTeksinSen GALATASARAY\u0131m","url":"http:\/\/twitter.com\/search?q=%22D%C3%BCnyadaTeksinSen+GALATASARAY%C4%B1m%22","promoted_content":null,"query":"%22D%C3%BCnyadaTeksinSen+GALATASARAY%C4%B1m%22","events":null},{"name":"D\u00fcnyan\u0131n TekHarikas\u0131s\u0131n FENERBAH\u00c7EM","url":"http:\/\/twitter.com\/search?q=%22D%C3%BCnyan%C4%B1n+TekHarikas%C4%B1s%C4%B1n+FENERBAH%C3%87EM%22","promoted_content":null,"query":"%22D%C3%BCnyan%C4%B1n+TekHarikas%C4%B1s%C4%B1n+FENERBAH%C3%87EM%22","events":null},{"name":"MustafaKemalin\u0130zindeyiz \u00c7\u00fcnk\u00fcFenerbah\u00e7eliyiz","url":"http:\/\/twitter.com\/search?q=%22MustafaKemalin%C4%B0zindeyiz+%C3%87%C3%BCnk%C3%BCFenerbah%C3%A7eliyiz%22","promoted_content":null,"query":"%22MustafaKemalin%C4%B0zindeyiz+%C3%87%C3%BCnk%C3%BCFenerbah%C3%A7eliyiz%22","events":null}],"as_of":"2013-07-20T10:51:45Z","created_at":"2013-07-20T10:45:24Z","locations":[{"name":"Turkey","woeid":23424969}]}]

我的问题是如何将此数组字符串转换为 html。根本没有适当的php经验。

4

2 回答 2

0

您得到的响应是 JSON。

曾经能够以 XML、RSS 等方式获得响应,但现在您将收到的唯一响应类型是 JSON。

PHP 有多种处理 JSON 的方法。要对数据进行编码,您可以使用json_encode(). 但是,您想对其进行解码,因此您需要执行以下操作:

var_dump(json_decode($yourData));

这会将数据转储到浏览器,以便您可以查看必须使用的内容。

您可以使用循环遍历此数据foreach()

请记住,假设您json_decode()的结果为$yourData

  • 要访问数组属性,请使用:$yourData['propertyName']
  • 要访问对象属性,请使用:$yourData->propertyName
于 2013-07-20T18:29:44.500 回答
0

您可以将其输入json_decode()函数
,您将获得一个可以根据需要进行管理的数组。

于 2013-07-20T11:08:29.697 回答