douweng1935 2011-12-14 20:04
浏览 73
已采纳

我该如何读取这个数组(“stdClass Object”)

I am using the Quizlet API 2.0, and I am pretty new to this

How do I read a value(s) from something like this:

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 ) ) )

For instance, if I want to get the name of that first set, "Learn Spanish with Cats", how do I echo it via variable?

It already converts the JSON to an array I think:

$data = json_decode($json);
  • 写回答

5条回答 默认 最新

  • douyi6960 2011-12-14 20:06
    关注

    Your object is not an array, but rather, well, an Object. So use the -> operator to access its properties:

    echo $data->name;
    

    It contains a property which itself is an array of additional objects. For example, to get the URL of id 6081999, you would do:

    echo $data->sets[0]->url;
    // http://quizlet.com/6081999/lesson-4-with-catsdogs-flash-cards/
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥15 键盘指令混乱情况下的启动盘系统重装
  • ¥40 复杂的限制性的商函数处理