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

  • Home
  • SEARCH
  • 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 6709493
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:53:19+00:00 2026-05-26T07:53:19+00:00

Disclaimer: I am fairly new to using json. I am trying to use php

  • 0

Disclaimer: I am fairly new to using json.

I am trying to use php to receive json data from an iPAd application. I know how to convert json to an array in php, but how do I actually receive it and store it into a variable so it can be decoded?

Here are a couple examples that I have tried based on google and stackoverflow searches.

$json_request = @file_get_contents('php://input'); 
$array = json_decode($json_request);

AND ALSO

$array = json_decode($_POST['data'], true);

Any suggestions?

  • 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-05-26T07:53:19+00:00Added an answer on May 26, 2026 at 7:53 am

    You have the basic idea already.

    you should test that the value is set and also strip extra slashes from the incoming string before trying to parse it as JSON.

    if(isset($_POST['data'])){
      $array = json_decode(stripslashes($_POST['data']),true);
      //$array now holds an associative array
    }//Data Exists
    

    It also would not be a bad idea before you start working with the array to test that the call to json_decode() was successful by ensuring that $array isn’t null before use.

    If you do not fully trust the integrity of the information being sent you should do extended checking along the way instead of trusting that a given key exists.

    if($array){ // Or (!is_null($array)) Or (is_array($array)) could be used
      //Process individual information here
    
      //Without trust
      if(isset($array['Firstname'])){
        $CustomerId = $array['Firstname'];
      }//Firstname exists
    }//$array is valid
    

    I in-particular like to verify information when I am building queries dynamically for information that may not be required for a successful db insert.

    In the above example $_POST['data'] indicates that what ever called the PHP script did so passing the JSON string using the post method in a variable identified as data.

    You could check more generically to allow flexibility in the sending method by using the $_REQUEST variable, or if you know it is coming as via the get method you can check $_GET. $_REQUEST holds all incoming parameters from both get and post.

    If you don’t know what the name of the variable coming in is and want to play really fast and loose you could loop over the keys in $_REQUEST trying to decode each one and use the one that successfully decoded (if any). [Note: I’m not encouraging this]

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

Sidebar

Related Questions

Disclaimer: super new to rails. I'm using Rails 3.2 Anyways, I'm trying to create
Disclaimer : I'm new to web development. Scenario : I've built an application using
Disclaimer: I'm fairly new to python! If I want all the lines of a
As a disclaimer I'd like to state that I'm fairly new to Objective-C and
Disclaimer: I'm fairly new to AJAX! I've looked around, and I'm not sure which
[Disclaimer: I am new to PHP, and I am just learning, so please no
Disclaimer: Never used php in my life. New to Unix and Jenkins I have
Disclaimer: I'm new to the REST school of thought, and I'm trying to wrap
Disclaimer: I'm a new convert to iOS, so please feel free to tell me
Disclaimer: the following is a sin against XML. That's why I'm trying to change

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.