The Slim Framework support forum has moved to http://discourse.slimframework.com. This Tender forum is no longer maintained or monitored.

nested array in json response

John H's Avatar

John H

19 Apr, 2013 07:18 PM

I have a json response that looks like:

{
   "name":"john",
   "city":"pittsburgh",
   "fav_things":[
      {
         "first_color":"blue",
         "second_color":"green",
         "third_color":"white"
      },
      {
         "fourth_color":"black",
         "fifth_color":"orange",
         "sixth_color":"brown"
      }
   ],
   "active":true
}

As you can see, the fav_things property is a nested array.

Up until now, I have had no problems with single properties updating in my database using Slim. I'm stuck on how to best update this array of properties as ONE into a row on my mysql db.

The error message I receive when Slim tries to accept this response and update the db is:

Type: ErrorException Code: 8
Message: Array to string conversion

How can I instruct Slim or my mysql code to interpret this nested array correctly?

my current code looks like

$sql = "UPDATE users SET
name=:name,
city=:city,
fav_things=:fav_things,
active=:active,
WHERE id=:id

$request = $app->request();
$response = $request->getBody();
$response = json_decode($response);

$STH  = $db->prepare($sql);
$STH->bindParam("name", $response->name);
$STH->bindParam("name", $response->city);
$STH->bindParam("name", $response->fav_things);
$STH->bindParam("name", $response->active);
$STH->execute();

Can anyone help me figure out how to get this fav_things nested property working?

Thanks! Any help is much appreciated!

John

Showing page 3 out of 3. View the first page

  1. 61 Posted by mahi on 01 Feb, 2017 10:44 AM

    mahi's Avatar

    awesome applications for absolutely nothing from vShare App http://vsharedownloadpro.com If we speak about its attributes then this is an amazing nice.

  2. 62 Posted by liz on 11 Mar, 2017 05:44 AM

    liz's Avatar

    good download and install converted Mp3 sound data. http://peggoapp.com Peggo is a superior YouTube to MP3 songs nice.

  3. 63 Posted by ram on 22 May, 2017 10:04 AM

    ram's Avatar

    The application also makes it simple to obtain metadata information for Movies, https://kodidownloadtv.com/kodi-for-iphone-ipad-ios-download-app filter them as per their dream software application and also is made.

  4. 64 Posted by Anita on 07 Jan, 2020 05:57 PM

    Anita 's Avatar

    Problem Solved: Showtime Anytime Com Activate
    Showtimeanytime is one of the most entertaning channel that offers a wonerful stuff. If your are trying to activate the channel SHOWTIME on your streaming device such as Roku, Apple TV, Firestick, etc or a error code is in front of you and you dont know what to do just visit our website <a href="http://www.comactivateroku.com/2017/06/29/showtimeanytime-com-activate-roku-help/">visit here</a> or call our toll free no. 1-800-717-2062 and get the best solutions for any query regarding SHOWTIMEANYTIME com activate and even if you want any information regarding the activation of other channels.

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:

»

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac