相关疑难解决方法(0)

使用PHP接收JSON POST

我正在尝试在支付界面网站上收到JSON POST,但我无法对其进行解码.

当我打印:

echo $_POST;
Run Code Online (Sandbox Code Playgroud)

我明白了:

Array
Run Code Online (Sandbox Code Playgroud)

当我尝试这个时,我什么也得不到:

if ( $_POST ) {
    foreach ( $_POST as $key => $value ) {
        echo "llave: ".$key."- Valor:".$value."<br />";
    }
}
Run Code Online (Sandbox Code Playgroud)

当我尝试这个时,我什么也得不到:

$string = $_POST['operation'];
$var = json_decode($string);
echo $var;
Run Code Online (Sandbox Code Playgroud)

我尝试这个时得到NULL:

$data = json_decode( file_get_contents('php://input') );
var_dump( $data->operation );
Run Code Online (Sandbox Code Playgroud)

当我做:

$data = json_decode(file_get_contents('php://input'), true);
var_dump($data);
Run Code Online (Sandbox Code Playgroud)

我明白了:

NULL
Run Code Online (Sandbox Code Playgroud)

JSON格式是(根据支付站点文档):

{
   "operacion": {
       "tok": "[generated token]",
       "shop_id": "12313",
       "respuesta": "S",
       "respuesta_details": "respuesta S",
       "extended_respuesta_description": "respuesta extendida",
       "moneda": "PYG",
       "monto": "10100.00",
       "authorization_number": "123456",
       "ticket_number": "123456789123456", …
Run Code Online (Sandbox Code Playgroud)

php post json

268
推荐指数
8
解决办法
40万
查看次数

在Swift3中发送JSON POST请求

在我的应用程序中,我正在尝试使用json数据发出http post请求.以下json必须转移到api

{ 
 "Password":"123456",   
 "Email":"test@gmail.com"
}
Run Code Online (Sandbox Code Playgroud)

这是我执行此任务的代码

let dict = ["Email": "test@gmail.com", "Password":"123456"] as [String: Any]
if let jsonData = try? JSONSerialization.data(withJSONObject: dict, options: []) {


    let url = NSURL(string: "http://xxxxxxxxx.net/api/Login")!
    let request = NSMutableURLRequest(url: url as URL)
    request.httpMethod = "POST"

    request.httpBody = jsonData

    let task = URLSession.shared.dataTask(with: request as URLRequest){ data,response,error in
        if error != nil{
           print(error?.localizedDescription)
           return
        }

        do {
            let json = try JSONSerialization.jsonObject(with: data!, options: .mutableContainers) as? NSDictionary

            if let parseJSON = json {
                   let resultValue:String …
Run Code Online (Sandbox Code Playgroud)

json ios nsurlsession swift

11
推荐指数
1
解决办法
2万
查看次数

标签 统计

json ×2

ios ×1

nsurlsession ×1

php ×1

post ×1

swift ×1