SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: Json Help

  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 Help

    Hi

    I have the following Json code i need to extract the message ID and status from it

    Code:
    Array
    (
        [test_mode] => 1
        [balance] => 150
        [batch_id] => 0
        [cost] => 1
        [num_messages] => 1
        [message] => Array
            (
                [num_parts] => 1
                [sender] => 447777777777
                [content] => 447777777777
            )
    
        [receipt_url] => 
        [custom] => 
        [messages] => Array
            (
                [0] => Array
                    (
                        [id] => 1
                        [recipient] => 0
                    )
    
            )
    
        [status] => success
    )
    how would i extract it as i was using the below but i think the API has been updated with a slightly different response.

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

    if (
    $jsonData->status === 'success') {
        
        
    // Grab Message ID
        
    foreach($jsonData->messages as $txtid)
      {
       
    // Got Message ID
       // Success code
        
    echo ('Sent: message to '.$to.' from '.$txtid.'');
      } 

  2. #2
    Always A Novice bronze trophy
    K. Wolfe's Avatar
    Join Date
    Nov 2003
    Location
    Columbus, OH
    Posts
    2,182
    Mentioned
    67 Post(s)
    Tagged
    2 Thread(s)
    Make it an array so it's easier to work with:

    PHP Code:
    $response json_decode($responsetrue); 
    It looks like this API has the possibility of returning multiple messages to you, so I don't think you just want to statically retrieve the first one.

    PHP Code:
    $response json_decode($responsetrue);

    $messageIds = array();
    foreach(
    $response['messages'] as $message) {
        
    array_push($messageIds$message['id']);
    }

    print_r($messageIds); 
    Side note, is this API for velti / air2web?

  3. #3
    SitePoint Zealot txt3rob's Avatar
    Join Date
    Jul 2013
    Location
    Liverpool UK
    Posts
    199
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Cheers dude no mate it is www.textlocal.co.uk their api for sending SMS

    I will look in to that bit of code you have given now


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
  •