用PHP解析json(parse json with php)
我是一个php newb,并且在理解如何解析json api返回时遇到一些问题。 这是json的片段:
{ "results": [ { "list_name": "", "display_name": "", "updated": "", "bestsellers_date": "", "published_date": "", "isbns": [ { "isbn10": "", "isbn13": "" }, { "isbn10": "", "isbn13": "" } ], "book_details": [ { "title": "Book author", "description": "Book description"", "contributor": "", "author": "Book author", "contributor_note": "", "price": , "age_group": "", "publisher": "", "primary_isbn13": "1010101010", "primary_isbn10": "1010101010101" } ], "reviews": [ { "book_review_link": "", "first_chapter_link": "", "sunday_review_link": "", "article_chapter_link": "" } ] },
这是我到目前为止的PHP ...
<?php $json=file_get_contents('the url for the api return'); // create array $json_a=json_decode($json,true); foreach($json_a[results] as $r) { echo ' List: '.$r[list_name].' <br /> Title: '.$r[title].' <br> Description: '.$r[description].' <br /> <br /> '; } ?>
我从api返回,它为'list_name'提供了正确的值,但'title'和'description'仍未填充; 所以,我知道我没有正确访问这些子键(?)。 获取这些元素的正确语法是什么?
真的很感谢你们所提供的任何指导。 提前致谢。
I'm a php newb and having some problems understanding how to parse a json api return. Here is a snippet of the json:
{ "results": [ { "list_name": "", "display_name": "", "updated": "", "bestsellers_date": "", "published_date": "", "isbns": [ { "isbn10": "", "isbn13": "" }, { "isbn10": "", "isbn13": "" } ], "book_details": [ { "title": "Book author", "description": "Book description"", "contributor": "", "author": "Book author", "contributor_note": "", "price": , "age_group": "", "publisher": "", "primary_isbn13": "1010101010", "primary_isbn10": "1010101010101" } ], "reviews": [ { "book_review_link": "", "first_chapter_link": "", "sunday_review_link": "", "article_chapter_link": "" } ] },
And here's the php I have so far...
<?php $json=file_get_contents('the url for the api return'); // create array $json_a=json_decode($json,true); foreach($json_a[results] as $r) { echo ' List: '.$r[list_name].' <br /> Title: '.$r[title].' <br> Description: '.$r[description].' <br /> <br /> '; } ?>
I'm getting a return from the api and it's providing the correct value for 'list_name', but 'title' and 'description' remain unpopulated; so, I know I'm not accessing those subkeys(?) correctly. What is the correct syntax for getting at those elements?
Really appreciate any guidance y'all can provide on this. Thanks in advance.
原文:https://stackoverflow.com/questions/7355633
最满意答案
不知道我是否正确理解问题,而不是确认只有一个复选框可选中的复选框列表,使用带Radiobuttons的RadioGroup。 您可以将多个RadioButton添加到RadioGroup中,然后只能选择一个RadioButton。
Not sure if I understand the question correctly but instead of a list of checkboxes where only one checkbox is checkable use a RadioGroup with Radiobuttons. You can have multiple RadioButtons which you add to a RadioGroup and then only one RadioButton can be selected.
相关问答
更多-
使用单选按钮(Working with Radio Buttons)[2022-07-08]
您的表格首次打开时,您唯一选中选择哪一个,用户没有机会选择一个,您需要创建一个选择更改事件 顺便说一句, else if在两行上可能创建一个嵌套的if语句而不是else if else 。 你可以做到这一点的一种方法是, public Airplane_Simulation() { InitializeComponent(); CheckedChanged(); rbZero.CheckedChanged += (s,e) => { Check ... -
事实证明这是一个简单的解决方案。 以下是上述问题的XAML部分已更改: