开发者

Problem getting data from JSON on PHP page

I send request like

$.ajax({
    url: 'php_scripts/reload_fancoils.php',
    type: 'POST',
    dataType: 'json',
    data:parameters,
    success: function(data){
        //alert(data);
        console.log(data);
    },
    error:function (xhr, ajaxOptions, thrownError){
        alert('statusText='+xhr.statusText+' responseText='+xhr.responseText);
    }   

});

where parameters are

{
    "command": "write_plan_to_db",
    "fan_coil_id": 44444,
    "plan": {
        "point开发者_开发百科s": {
            "mon": [
                "{\"start_time\":0, \"end_time\":840,\"mode\":0}",
                "{\"start_time\":840, \"end_time\":1440,\"mode\":2}"
            ],
            "tue": [
                "{\"start_time\":0, \"end_time\":1440,\"mode\":0}"
            ],
            "wed": [
                "{\"start_time\":0, \"end_time\":1440,\"mode\":1}"
            ],
            "thu": [
                "{\"start_time\":0, \"end_time\":1440,\"mode\":2}"
            ],
            "fri": [
                "{\"start_time\":0, \"end_time\":1440,\"mode\":4}"
            ],
            "sat": [
                "{\"start_time\":0, \"end_time\":1440,\"mode\":0}"
            ],
            "sun": [
                "{\"start_time\":0, \"end_time\":1440,\"mode\":1}"
            ]
        },
        "modes": {
            "mode_1": {
                "temperature_set_point": 18,
                "max_positive_variation": 0,
                "min_positive_variation": 0,
                "max_fan_speed": 4
            },
            "mode_2": {
                "temperature_set_point": 18,
                "max_positive_variation": 0,
                "min_positive_variation": 0,
                "max_fan_speed": 4
            },
            "mode_3": {
                "temperature_set_point": 18,
                "max_positive_variation": 0,
                "min_positive_variation": 0,
                "max_fan_speed": 4
            },
            "mode_4": {
                "temperature_set_point": 18,
                "max_positive_variation": 0,
                "min_positive_variation": 0,
                "max_fan_speed": 4
            },
            "mode_5": {
                "temperature_set_point": 18,
                "max_positive_variation": 0,
                "min_positive_variation": 0,
                "max_fan_speed": 4
            }
        }
    }
}

How to read values for 'mode_1' on server side, php page ?


use json_decode function, for example

$var = json_decode($_POST['parameters']);

var_dump($var);


$plan = json_decode($_POST['plan']);
$mode1 = $plan->modes->mode_1;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜