如何获取jSON API数据并将其作为变量存储在PHP中

时间:2015-06-23 08:34:23

标签: php json api decode

我有一个url,它返回一组数据作为jSON对象,我想解码返回的数据并在PHP中放入变量。我不知道该怎么做..

这是该url作为结果返回的对象

{
  "result" : "ok",
  "tuc" : [ {
    "meanings" : [ {
      "language" : "en",
      "text" : "unwilling to work"
    }, {
      "language" : "en",
      "text" : "relaxed or leisurely"
    }, {
      "language" : "en",
      "text" : "eye: squinting because of weak muscles"
    }, {
      "language" : "en",
      "text" : "Unwilling to do work or make an effort."
    }, {
      "language" : "en",
      "text" : "Unwilling to do work or make an effort."
    }, {
      "language" : "en",
      "text" : "Requiring little or no effort."
    }, {
      "language" : "en",
      "text" : "Relaxed or leisurely."
    }, {
      "language" : "en",
      "text" : "(optometry) Of an eye, squinting because of a weakness of the eye muscles."
    }, {
      "language" : "en",
      "text" : "(cattle brands) Turned so that the letter is horizontal instead of vertical."
    } ],
    "meaningId" : null,
    "authors" : [ 60172 ]
  } ],
  "phrase" : "lazy",
  "from" : "en",
  "dest" : "en",
  "authors" : {
    "60172" : {
      "U" : "http://www.omegawiki.org/",
      "id" : 60172,
      "N" : "omegawiki",
      "url" : "https://glosbe.com/source/60172"
    }
  }
}

我希望前5个数据作为我的结果,

$text1 = "unwilling to work";
$text2 = "relaxed or leisurely";
$text3 = "eye: squinting because of weak muscles"
$text4 = "Unwilling to do work or make an effort."
$text5 = "Unwilling to do work or make an effort."

数据重复不是问题。

1 个答案:

答案 0 :(得分:0)

您可以将PHP中的对象转换为关联数组,在Stack溢出时已经有很多关于它的问题。