我将如何读这阵列(; stdClass的对象") [英] How would I read this array ("stdClass Object")

查看:138
本文介绍了我将如何读这阵列(; stdClass的对象")的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是Quizlet API 2.0,而我pretty新本

我读东西值(S),像这样怎么办:

  stdClass的对象([ID] => 102269 [名] =>!与猫学习西班牙语[set_count] => 3 [USER_COUNT] => 10 CREATED_DATE] => 1308035691【is_public] => 1 [has_password] => has_​​access] => 1 [has_discussion] => 1 [member_add_sets] => 1 [说明] =>这集是专为西班牙烧录卡套有关猫的图像作为集定义[设置] =方式>阵列([0] => stdClass的对象([ID] => 6081999 [URL] => http://quizlet.com/6081999 /课-4与 -  catsdogs闪存卡/ [标题] =>第4课(带猫+狗)[CREATED_BY] => wsvincent [term_count] => 33 [CREATED_DATE] => 1311984796【MODIFIED_DATE ] => 1312490710【has_images] => 1 [主题] =>数组([0] =>西班牙语猫犬)[知名度] =>公共 =基团[has_access] => 1)[1] => stdClass的对象([ID] => 5855751 [URL] => http://quizlet.com/5855751/paso-a-paso-book-1-chapter-4-flash-卡/ [标题] =>埃尔帕索埃尔帕索一书1章4 CREATED_BY] => catdawg426 [term_count] => 30 CREATED_DATE] => 1307761267 [MODIFIED_DATE] => 1307819129 [has_images] => 1 [主题] =>阵列([0] =>西班牙语)[知名度] =>公共 => only_me [has_access] => 1)[2] => stdClass的对象([ID] => 5873819 [URL] => http://quizlet.com/5873819/los-gatos-de-viaje-flash-cards/ [标题] =>洛斯加托斯德VIAJE [! CREATED_BY] => tiffreja [term_count] => 21 [CREATED_DATE] => 1307996657【MODIFIED_DATE] => 1307996796【has_images] => 1 [主题] =>数组([0] =>西班牙语[ 1] =>语言[2] =>外商)[知名度] =>公共 => only_me [has_access] => 1))[会员] =>阵列([0] => stdClass的对象([用户名] => philfreo [作用] =>创作者[email_notification] => 1)[1] => stdClass的对象([用户名] => milkncookies [作用] =>成员[email_notification] => 1)[2] => stdClass的对象([用户名] => Icypaw [作用] =>成员[email_notification] =>)[3] => stdClass的对象([用户名] => luckycat10 [作用] =>成员[email_notification] =>)[4] => stdClass的对象([用户名] => jeffchan [作用] =>成员[email_notification] =>)[5] => stdClass的对象([用户名] => catchdave [作用] =>成员[email_notification] => 1)[6] => stdClass的对象([用户名] => tiffreja [作用] =>成员[email_notification] => 1)[7] => stdClass的对象([用户名] => catdawg426 [作用] =>成员[email_notification] => 1)[8] => stdClass的对象([用户名] => ihaque [作用] =>成员[email_notification] => 1)[9] => stdClass的对象([用户名] => jalenack [作用] =>会员[email_notification] => 1)))

举例来说,如果我想要得到的第一套,学习西班牙语与猫的名字,我怎么通过可变呼应呢?

这已经是JSON转换为一个数组,我认为:

  $数据= json_de code($ JSON);


解决方案

您的对象不是一个数组,而是很好,一个对象。因此,使用 - > 操作符来访问它的属性。

 回声$数据 - >名;

它包含一个属性,它本身是其他对象的阵列。例如,为了获得ID 6081999的网址,你会怎么做:

 回声$数据 - >设置[0]  - >网址;
// http://quizlet.com/6081999/lesson-4-with-catsdogs-flash-cards/

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

解决方案

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/

这篇关于我将如何读这阵列(; stdClass的对象")的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆