如何使用随机值数组获取循环JSON值量,请使用PHP

{

  "success": 1,

  "return": {

    "1400151861513776": {

      "pair": "edc_btc",

      "type": "buy",

      "amount": 138959.22155687,

      "rate": 0.00000085,

      "timestamp_created": "1556464987",

      "status": 0

    },

    "1400151861456538": {

      "pair": "edc_btc",

      "type": "buy",

      "amount": 4115.53246448,

      "rate": 0.00000085,

      "timestamp_created": "1556463520",

      "status": 0

    },

    "1400151861402138": {

      "pair": "edc_btc",

      "type": "buy",

      "amount": 252.29423504,

      "rate": 0.00000085,

      "timestamp_created": "1556462106",

      "status": 0

    },

    "1400151861205651": {

      "pair": "edc_btc",

      "type": "buy",

      "amount": 5735.02289537,

      "rate": 0.00000085,

      "timestamp_created": "1556457111",

      "status": 0

    },

    "1400151861064946": {

      "pair": "edc_btc",

      "type": "buy",

      "amount": 608.2294235,

      "rate": 0.00000085,

      "timestamp_created": "1556453555",

      "status": 0

    },

    "1400151860984352": {

      "pair": "edc_btc",

      "type": "buy",

      "amount": 13553.51532229,

      "rate": 0.00000085,

      "timestamp_created": "1556451515",

      "status": 0

    },

    "1400151860967764": {

      "pair": "edc_btc",

      "type": "buy",

      "amount": 49475.62404601,

      "rate": 0.00000085,

      "timestamp_created": "1556451103",

      "status": 0

    },

  

如何获得循环值的数量。此数组每次都有随机值1400151861513776..change。


我用的是PHP代码json_decode....


叮当猫咪
浏览 228回答 2
2回答

暮色呼如

您可以json_decode用来将JSON转换为数组。PHP json_decode()$jsonToArray = json_decode($json,true); // $json has the `JSON`如果您需要与key,则amount可以使用array_walk PHP array_walk()$jsonToArray = json_decode($json,true);$res = [];array_walk($jsonToArray['return'], function($v, $k) use (&$res){  $res[$k] = $v['amount'];});输出:-Array(  [1400151861513776] => 138959.22155687  [1400151861456538] => 4115.53246448   .......   .......  [2400151857916444] => 400000  [2400151857916059] => 400000)或者如果不需要key,则只能amount使用array_map PHP array_map()$jsonToArray = json_decode($json,true);$res = [];array_map(function($v) use(&$res){  $res[] = $v['amount'];}, $jsonToArray['return']);输出 :- Array(  [0] => 138959.22155687  [1] => 4115.53246448   .......   .......)
打开App,查看更多内容
随时随地看视频慕课网APP