Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8648861
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T13:24:52+00:00 2026-06-12T13:24:52+00:00

I have some JSON that I am trying to decode — it is correctly

  • 0

I have some JSON that I am trying to decode — it is correctly extracting the value, but also generating an error.

Here is the var_dump:

["success"]=>
bool(true)
["providers"]=>
array(2) {
[0]=>
object(stdClass)#5 (15) {
  ["address1"]=>
  string(14) "3240 W Lake St"
  ["address2"]=>
  NULL
  ["city"]=>
  string(11) "Minneapolis"
  ["crossStreet"]=>
  string(26) "Lake Street & Market Plaza"
  ["description"]=>
  string(55) "test location28402 description of services/prices/hours"
  ["distance"]=>
  float(0.42900015862223)
  ["lat"]=>
  float(44.948469)
  ["lon"]=>
  float(-93.321155)
  ["name"]=>
  string(17) "testlocation28402"
  ["phone"]=>
  string(10) "6125551212"
  ["precise"]=>
  bool(true)
  ["state"]=>
  string(2) "MN"
  ["url"]=>
  string(41) "http://www.testlocation28402.com?id=28402"
  ["urlCaption"]=>
  string(25) "www.testlocation28402.com"
  ["zip"]=>
  string(9) "554164512"
}
[1]=>
object(stdClass)#6 (15) {
  ["address1"]=>
  string(19) "4335 Excelsior Blvd"
  ["address2"]=>
  NULL
  ["city"]=>
  string(16) "Saint Louis Park"
  ["crossStreet"]=>
  NULL
  ["description"]=>
  string(55) "test location26358 description of services/prices/hours"
  ["distance"]=>
  float(0.91979730006713)
  ["lat"]=>
  float(44.935773)
  ["lon"]=>
  float(-93.33489)
  ["name"]=>
  string(17) "testlocation26358"
  ["phone"]=>
  string(10) "6125551212"
  ["precise"]=>
  bool(true)
  ["state"]=>
  string(2) "MN"
  ["url"]=>
  string(41) "http://www.testlocation26358.com?id=26358"
  ["urlCaption"]=>
  string(25) "www.testlocation26358.com"
  ["zip"]=>
  string(9) "554164811"
}
  } 
["errors"]=>array(0) {
}
}

Above is the var_dump of the variable $json. I am trying to extract the CITY field with:

$json = json_decode($surescript);

foreach ($json as $providers){
foreach($providers as $onespot) {
echo "*";
echo $onespot->city;
echo "\n";
}
}

This outputs:

Warning: Invalid argument supplied for foreach() in /home/content/96/7973196/html/channels/MIL432/storeFinder_2.php on line 153
*Minneapolis
*Saint Louis Park

So, it is getting the correct nested variable, but also throwing off an error on the second foreach loop.

What am I doing incorrectly?

Thanks in advance for your help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T13:24:53+00:00Added an answer on June 12, 2026 at 1:24 pm

    You’re iterating over everything in the JSON in your outer loop, meaning that it’s trying to parse the success section, the providers section, as well as the errors section.

    When you try to parse the success, you can’t iterate over the contents in the inner loop, hence the error. The errors section is an array, so you can iterate over it – since there’s nothing in it, no error/warning for trying to access city, which wouldn’t exist in it.

    To only parse the providers:

    $json = json_decode($surescript);
    
    foreach ($json->providers as $provider){
        echo "*";
        echo $provider->city;
        echo "\n";
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some JSON code in a string that I am trying to parse.
Inside my .aspx I have some JSON code that looks like this: function someFunctionName()
I have some data that I have to serialize to JSON. I'm using JSON.NET.
I have a spring action that I am rendering some json from the controller,
I have an jQuery JSON request, that loads some JSON from another server (ex.
I have a function that returns json (networks_function.php builds up some arrays and encodes
Some code that I don't have control over is overriding the global JSON object
I have an iPhone app that uses the json-framework . I moved some of
I have a var that has some JSON data: A = <<{\job\: {\id\: \1\}}>>.
I'm trying to write up a simple jquery script that parses some JSON and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.