102269 [name] => Learn Spanis-6ren">
gpt4 book ai didi

php - 我将如何读取此数组 ("stdClass Object")

转载 作者:可可西里 更新时间:2023-10-31 23:55:05 24 4
gpt4 key购买 nike

我正在使用 Quizlet API 2.0,对此我还很陌生

我如何从这样的东西中读取值:

stdClass Object ( [id] => 102269 [name] => Learn Spanish with Cats! [set_count] => 3 [user_count] => 10 [created_date] => 1308035691 [is_public] => 1 [has_password] => [has_access] => 1 [has_discussion] => 1 [member_add_sets] => 1 [description] => This set is exclusively for Spanish flashcard sets with relevant cat images as the set definitions. [sets] => Array ( [0] => stdClass Object ( [id] => 6081999 [url] => http://quizlet.com/6081999/lesson-4-with-catsdogs-flash-cards/ [title] => Lesson 4 (with cats+dogs) [created_by] => wsvincent [term_count] => 33 [created_date] => 1311984796 [modified_date] => 1312490710 [has_images] => 1 [subjects] => Array ( [0] => spanish cats dogs ) [visibility] => public [editable] => groups [has_access] => 1 ) [1] => stdClass Object ( [id] => 5855751 [url] => http://quizlet.com/5855751/paso-a-paso-book-1-chapter-4-flash-cards/ [title] => Paso a Paso Book 1 Chapter 4 [created_by] => catdawg426 [term_count] => 30 [created_date] => 1307761267 [modified_date] => 1307819129 [has_images] => 1 [subjects] => Array ( [0] => spanish ) [visibility] => public [editable] => only_me [has_access] => 1 ) [2] => stdClass Object ( [id] => 5873819 [url] => http://quizlet.com/5873819/los-gatos-de-viaje-flash-cards/ [title] => Los Gatos de Viaje! [created_by] => tiffreja [term_count] => 21 [created_date] => 1307996657 [modified_date] => 1307996796 [has_images] => 1 [subjects] => Array ( [0] => spanish [1] => language [2] => foreign ) [visibility] => public [editable] => only_me [has_access] => 1 ) ) [members] => Array ( [0] => stdClass Object ( [username] => philfreo [role] => creator [email_notification] => 1 ) [1] => stdClass Object ( [username] => milkncookies [role] => member [email_notification] => 1 ) [2] => stdClass Object ( [username] => Icypaw [role] => member [email_notification] => ) [3] => stdClass Object ( [username] => luckycat10 [role] => member [email_notification] => ) [4] => stdClass Object ( [username] => jeffchan [role] => member [email_notification] => ) [5] => stdClass Object ( [username] => catchdave [role] => member [email_notification] => 1 ) [6] => stdClass Object ( [username] => tiffreja [role] => member [email_notification] => 1 ) [7] => stdClass Object ( [username] => catdawg426 [role] => member [email_notification] => 1 ) [8] => stdClass Object ( [username] => ihaque [role] => member [email_notification] => 1 ) [9] => stdClass Object ( [username] => jalenack [role] => member [email_notification] => 1 ) ) )

例如,如果我想获取第一组的名称“Learn Spanish with Cats”,我该如何通过变量回显它?

我认为它已经将 JSON 转换为数组:

$data = json_decode($json);

最佳答案

您的对象不是数组,而是对象。所以使用 -> 运算符来访问它的属性:

echo $data->name;

它包含一个属性,该属性本身是一个附加对象数组。例如,要获取 id 6081999 的 URL,您可以这样做:

echo $data->sets[0]->url;
// http://quizlet.com/6081999/lesson-4-with-catsdogs-flash-cards/

关于php - 我将如何读取此数组 ("stdClass Object"),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8510917/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com