首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从具有子数组的json子数组中获取数据

从具有子数组的json子数组中获取数据
EN

Stack Overflow用户
提问于 2014-01-15 19:21:17
回答 1查看 695关注 0票数 2

我想从表中的JSON代码中检索长数据,它看起来像

代码语言:javascript
复制
{"def":{"short":"the first, in place, time, order or rank (specifically, a firstfruit)","long":["first, beginning, best, chief",["beginning","first","chief","choice part"]]},"deriv":"from the same as H7218","pronun":{"ipa":"reʔˈʃɪi̯t̪","ipa_mod":"ʁeʔˈʃiːt","sbl":"rēʾšît","dic":"ray-SHEET","dic_mod":"ray-SHEET"}}

{"def":{"short":"the sky (as aloft; the dual perhaps alluding to the visible arch in which the clouds move, as well as to the higher ether where the celestial bodies revolve)","long":["heaven, heavens, sky",["visible heavens, sky",["as abode of the stars","as the visible universe, the sky, atmosphere, etc"],"Heaven (as the abode of God)"]]},"deriv":"dual of an unused singular שָׁמֶה; from an unused root meaning to be lofty","pronun":{"ipa":"ʃɔː.mɑˈjɪm","ipa_mod":"ʃɑː.mɑˈjim","sbl":"šāmayim","dic":"shaw-ma-YIM","dic_mod":"sha-ma-YEEM"}}

更多的数据,我做了这个:

代码语言:javascript
复制
$data_result = json_decode($data, true);

$long_definition_1 = $data_result['def']['long'][0];

$compter_long =  count($data_result['def']['long'][1]);


for($i=0; $i<$compter_long; $i++)
{

   $long_definition_1 .= ', ';  
   $long_definition_1 .= $data_result['def']['long'][1][$i];

}

echo $long_definition_1;

它适用于第一行并显示:

代码语言:javascript
复制
Long Def 1 : first, beginning, best, chief, beginning, first, chief, choice part  

但是对于第二行和其他行,它发送给我这个错误。

代码语言:javascript
复制
Notice: Array to string conversion in E:\A - A - SITES ET SERVER\EasyPHP-DevServer-13.1VC9\data\localweb\BIBLES SQL BIBLEFORGE\BibleForgeDB-master\BibleForgeDB-master\brouillons.php on line 164

我找了好几天到处都找不到解决办法。我将非常感谢你的帮助。谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-01-15 19:42:07

因为在第二个数组中,也有一个数组

代码语言:javascript
复制
['def']['long'][1][1]

因此,它不能将数组放入字符串中。

这是一个非常有用的网站,很容易看到json http://jsonviewer.stack.hu/中的内容。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21146332

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档