谷歌字体api/json/php/json_decode [英] Google font api / json /php /json_decode
本文介绍了谷歌字体api/json/php/json_decode的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个来自Google api的json变量:
I have this json var from google api :
$json='
{
"kind": "webfonts#webfontList",
"items": [
{
"kind": "webfonts#webfont",
"family": "Jockey One",
"variants": [
"400"
],
"subsets": [
"latin",
"latin-ext"
]
},
{
"kind": "webfonts#webfont",
"family": "Josefin Sans",
"variants": [
"100",
"100italic",
"300",
"300italic",
"400",
"400italic",
"600",
"600italic",
"700",
"700italic"
],
"subsets": [
"latin"
]
},
....
]
}';
我如何用php解码$ json以便显示如下信息:
How can i decode $json with php in order to display informations like this :
- 字体1:家族-变体-子集
- 字体2:家族-变体-子集
例如第二项:
- 字体家族:Josefin Sans |变体:100、100italic,300 ... |子集:拉丁语
谢谢
推荐答案
$data = json_decode($json,true);
$items = $data['items'];
$i = 0;
foreach ($items as $item) {
$i++;
$str = 'Font '.$i.' '.$item['family'].' Subsets:';
foreach ($item['variants'] as $variant) {
$str .= ' '.$variant.' ';
}
$str.= ' Variants';
foreach ($item['subsets'] as $subset) {
$str .= ' '.$subset;
}
echo $str.'<br />';
}
这正是您想要的.
这篇关于谷歌字体api/json/php/json_decode的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文