SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: Json

  1. #1
    SitePoint Zealot txt3rob's Avatar
    Join Date
    Jul 2013
    Location
    Liverpool UK
    Posts
    199
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Json

    I have the following if json returns suscessful

    PHP Code:
    // Process your response here
        
    $jsonData json_decode($response);

    if (
    $jsonData->status === 'success') {
    echo (
    'Sent'); 
    I need to also get the id number that will be in the returned value
    Code:
    {
    	"balance":1162,
    	"batch_id":123456789,
    	"cost":2,
    	"num_messages":2,
    	"message":{
    		"num_parts":1,
    		"sender":"Rob",
    		"content":"This is your message"
    	},
    	"messages":[{
    		"id":"1151346216",
    		"recipient":447123456789
    	},
    	{
    		"id":"1151347780",
    		"recipient":447987654321
    	}],
    	"status":"success"
    },
    i want to get the id value and set that as a variable id how would i go about this.

  2. #2
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,235
    Mentioned
    154 Post(s)
    Tagged
    0 Thread(s)
    which id do you want? the batch_id or the id of each message in the messages array?

  3. #3
    SitePoint Zealot txt3rob's Avatar
    Join Date
    Jul 2013
    Location
    Liverpool UK
    Posts
    199
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Id of the message

  4. #4
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,235
    Mentioned
    154 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    // Process your response here 
        
    $jsonData json_decode($response); 

    if (
    $jsonData->status === 'success') { 
      foreach(
    $jsonData->messages as $message)
      {
        echo 
    $message->id;
      } 

  5. #5
    SitePoint Zealot txt3rob's Avatar
    Join Date
    Jul 2013
    Location
    Liverpool UK
    Posts
    199
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Cheers for your help much appriciated!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •