2014-04-06 04:57
浏览 225


I'm building an API, and I need a little help, to understand how can I parse data from JSON request, here is my code:

<textarea style="width: 100%; height: 300px;" id="request_json">
    "0":" "

 function SubmitAPI() {
    var sendInfo = { 
      JSON    : $('#request_json').val(),
      URL     : $('#supplier_api_endpoint_JSON_Tour_List').val(),
      Type    : 'JSON Tour List'

$('#response_json').html("Calling API...");
       url: 'post_JSON.php', 
       type: "POST",
       data: JSON.stringify(sendInfo), // send the string directly
       success: function(response){
      var obj = jQuery.parseJSON( response );
    $('#response_validation').html( obj.json_valid );
          error: function(response) {

So I need to know how to receive "JSON.stringify(sendInfo)" in my php script post_JSON.php

Any idea ?

Thank you in advance,

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

2条回答 默认 最新

  • dou1908 2014-04-06 05:26

    I think you need to name you data string, something like...

    data: {info: JSON.stringify(sendInfo)},

    and in your php:

    $json_data = $_POST['info'];
    var_dump(json_decode($json_data, true));

    to get at that data using php, do something like:

    $postedData = json_decode($json_data, true); // turns json string into an object
    $requestType = $postedData['requestType']; 

    if you need to parse a returned json string with jquery you do something like this:

    var jsonStuff = jQuery.parseJSON( data );
    alert( jsonStuff.requestType);
    解决 无用
    打赏 举报

相关推荐 更多相似问题