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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T11:51:27+00:00 2026-06-14T11:51:27+00:00

I want to pass a JSON: {name:jason,age:20} in PHP though POST In RoR, I

  • 0

I want to pass a JSON: {"name":"jason","age":"20} in PHP though POST

In RoR, I can get the two values by using params["name"] & params["age"]

But I don’t know how to get them in PHP.

I understand that I can ‘translate’ the JSON string into associative array by using json_decode but I don’t know how to get the JSON string.

In my PHP code, I has tried something like this:

<?php
    $json_string = $_POST['params'];

    $json_object= json_decode($json_string);
    print_r($json_object);

    echo $json_object->name;
    echo " ";
    echo $json_object->age;
?>

Then I has tested the PHP with terminal and I got the correct result

curl -d 'params={"name":"jason", "age":"20"}' xxxx/test_json_decode.php

It works but it seems strange to me, because I didn’t set the 'Content-Type: application/json'

Is it the correct way to parse JSON in PHP?

  • 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-06-14T11:51:29+00:00Added an answer on June 14, 2026 at 11:51 am

    The content-type is only useful in certain cases, such as jquery doing a standard .post where you haven’t explicitly told it to expect a json response. A json string is just text, and the content-type is just a clue to the receiver. but you could still send a json string with image/jpeg and still decode it and get a native structure again.

    As long as what you pass into json_decode() is a valid JSON string, regardless of the mime-type it was sent with, it’ll be decoded into a native structure.

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

Sidebar

Related Questions

I Have two problem in this Case : I want to pass a JSON
I have following code and i want to pass additional parameter in JSON.getJSONfromURL() method
I want to pass parameters from PHP Command Line Interface, and then read in
I want to return the PHP token_get_all() function as JSON. I also want token_get_all
I want to pass a JSON data structure to an MVC (3) Controller, have
I have a javascript object which I want to pass to a PHP file
I have a more dimensional php array that i want to pass to a
I just simply want to return a JSON object (using ajax) from my server
I want to pass a serialized json object and returned it within custom Html
I want to pass label/value pair in Ajax .POST but cannot find any solution.

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.