0

i have response from API like this

  "user_settings": {..},
  "users_info": {
    "success": true,
    "data": {
      "notable_users_pcr": 0.245714,
      "users_with_pcr": 0.853978,
      "users_type": [
        {
          "code": "town_1",
          "weight": 0.134769
        },
        {
          "code": "town_2",
          "weight": 0.094154
        },
        {
          "code": "town_3",
          "weight": 0.16633
        },
        {
          "code": "town_4",
          "weight": 0.604747
        }
      ],
      "users_class": "low",
      "users_reachability": [
        {
          "code": "-500",
          "weight": 0.499692
        },
        {
          "code": "500-1000",
          "weight": 0.264352
        },
        {
          "code": "1000-1500",
          "weight": 0.101187
        },
        {
          "code": "1500-",
          "weight": 0.134769
        }
      ],

i use CURL to fetch the data json_decode and everything work, but i cant get the data from users_reachability

i try like this but users_reachability not work to fetch the data row 0, 1, 2, 3,

  $responeds = json_decode($authToken,true);
// Work
  $get_success = $responeds['users_info']['success'];
// try those but not work
  $get_success =  $responeds['users_info']['data']['users_type];
  $get_success =  $responeds['users_info']['data']['users_type][0];
  $get_success =  $responeds['users_info']['data']['users_type][][0];
  $get_success =  $responeds['users_info']['data']['users_type][''][0];

errors shows up

Warning: Undefined array key "users_info" ..
Warning: Trying to access array offset on value of type null in ..
Warning: Trying to access array offset on value of type null in ..
Warning: Trying to access array offset on value of type null in ..

The Goal how can i get the value from users_info -> data -> users_type -> 1 OR 2 OR 3

Your Common Sense
  • 156,878
  • 40
  • 214
  • 345
  • @YourCommonSense dear friend, How now i'll get the result if no body helps me. to understand the point exactly in my code? i followed the answerd you put but not exactly helps my point. anyway in this world we must only PAY to get what we looking for nothing for Free.. – Edward Bahnasi Jul 25 '22 at 14:22

1 Answers1

-1

users_reachability can be accessed just fine:

enter image description here

IVO GELOV
  • 13,496
  • 1
  • 17
  • 26
  • i face this errors `Warning: Undefined array key "users_info" in..` `Warning: Trying to access array offset on value of type null in` in localhost ? may i know why – Edward Bahnasi Jul 25 '22 at 13:55
  • Most probably because the string that you're providing to JSON_DECODE is not a valid JSON. – IVO GELOV Jul 25 '22 at 14:01
  • `$responeds = json_decode($authToken,true);$get_success = $responeds['users_info']['data']['users_type'][0];echo $get_success` this is what im doing but i got the error message ;( – Edward Bahnasi Jul 25 '22 at 14:07
  • Throw away your code and use the one from the screenshot - it certainly does work without any errors. OR, call `json_last_error_msg()` after `json_decode()` if you want to see whether your JSON was valid. – IVO GELOV Jul 26 '22 at 09:05