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 6837919
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:32:03+00:00 2026-05-26T23:32:03+00:00

I have some Json being returned from facebook which I’m then parsing in to

  • 0

I have some Json being returned from facebook which I’m then parsing in to an array using json _decode. The data ends up looking like this (this is just the snippet I’m interested in):

( [data] =>
     Array ( [0] => 
         Array ( 
             [id] => 1336269985867_10150465918473072 
             [from] => 
                 Array ( [name] => a name here 
                         [category] => Community 
                         [id] => 1336268295867 ) 
                         [message] => A message here

Now I’ve been able to iterate over this data and get what I need:

   $jsonDecoded = json_decode($json, true);
   $xmlOutput = '<?xml version="1.0"?><data><items>';
   foreach ($jsonDecoded as $e) {
       foreach ($e as $i) {
           $xmlOutput .= '<item><timestamp>' . $i['created_time'] . '</timestamp><title><![CDATA[ ' . $i['message'] .' ]]></title><link>' . $link . '</link><type>facebook</type></item>';
       }
   }

   $xmlOutput .= '</items></data>';

..up until now where I need to check on the from->id value.

I added this line in the second for each:

 foreach ($e as $i) {
     if($i['from']['id'] == '1336268295867') {

But this just gives me an error:

Fatal error: Cannot use string offset as an array in /Users/Desktop/Webs/php/getFeeds

Any ideas why? I’m sure this is the correct way to get at that value and in actual fact if I echo this out in my loop instead of doing the if statement above I get the value back:

$jsonDecoded = json_decode($json, true);
$xmlOutput = '<?xml version="1.0"?><data><items>';
foreach ($jsonDecoded as $e) {
    foreach ($e as $i) {
       echo $i['from']['id']  

This returns me all of the from->id values in the code returned from facebook and then following this I get the error:

133626829985867133626829985867133626829985867133626829985867195501239202133626829985867133626829985867133626829985867133626829985867133626829985867
Fatal error: Cannot use string offset as an array in /Users/Desktop/Webs/php/getFeeds.php on line 97

(line 97 is the echo line)

  • 1 1 Answer
  • 1 View
  • 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-05-26T23:32:03+00:00Added an answer on May 26, 2026 at 11:32 pm

    Your code makes a lot of assumptions about $i[‘from’][‘id’] and at least one of them is incorrect for at least one entry.
    Let’s add some tests:

    $jsonDecoded = json_decode($json, true);
    $xmlOutput = '<?xml version="1.0"?><data><items>';
    foreach ($jsonDecoded as $e) {
        if ( !is_array($e) ) {
            die('type($e)=='.gettype($e).'!=array');
        }
        foreach ($e as $i) {
            if ( !is_array($i) ) {
                die('type($i)=='.gettype($i).'!=array');
            }
            else if ( !array_key_exists('from', $i) ) {
                die('$i has no key "from"');
            }
            else if ( !is_array($i['from']) ) {
                die('type($i["from"])=='.gettype($i['from']).'!=array');
            }
            else if ( !array_key_exists('id', $i['from']) ) {
                var_dump($i);
                die('$i["from"] has no key "id"');
            }
    
            echo $i['from']['id'];
        }
    }
    

    And then you can add a var_dump(...) before the die(...) to take a look at the actual data.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following JSON data being returned, but for some reason, Javascript or
A] Problem summary: I have JSON data being returned from python to javascript. I
I have some data that I have to serialize to JSON. I'm using JSON.NET.
I have a REST api which dumps some json data (user info, etc). Now
I have a website where an ajax call will get some Json data from
I have some code that requests some JSON from an API. When data is
I have json data being returned as a collection: var foo = [6, 7,
Im trying to append some JSON data from the last.fm API, I have been
Hi i have some problem parsing the json in IOS. This is the json
I have an jQuery JSON request, that loads some JSON from another server (ex.

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.