从外部验证json帖子

时间:2013-07-22 10:04:52

标签: json codeigniter logging

我有从外部系统接收post json对象的脚本。 它应该接收以下的json对象:

{"data":[{"BegRecNbr": 81, "RecFrag": [{"Fields": {"mA": [1406.205078125, 1914.948486328125], "mB": [1769.690673828125, 1816.0640869140625, 1692.6290283203125, 744.02020263671875]}, "RecNbr": 81, "TimeOfRec": [731495520, 0]}], "TableNbr": 3}, {"BegRecNbr": 82, "RecFrag": [{"Fields": {"mA": [1406.19384765625, 1915.2742919921875], "mB": [1768.99462890625, 1815.36767578125, 1692.615478515625, 744.01434326171875]}, "RecNbr": 82, "TimeOfRec": [731496480, 0]}], "TableNbr": 3, "NbrOfRecs": 1}]}

我无法触摸外部系统,因此我只能在处理之前登录文件对象帖子。

我尝试使用CI中的log_message来记录文件,仅用于调试

log_message('debug','values json1: '.$_POST);
$log_my_post = var_export($_POST, TRUE); 
$log_my_post = str_replace(array("\r","\n"," "), '', $log_my_post); 
log_message('debug','values json2: '.$log_my_post);

在日志文件中,我只能看到

DEBUG - 2013-07-22 16:01:28 --> values json1: Array
DEBUG - 2013-07-22 16:01:28 --> values json2: array()

如何从外部系统查看发送到我脚本的数组的详细信息 这样我就可以验证发送的正确消息了吗?

感谢您的帮助。

问候

2 个答案:

答案 0 :(得分:0)

尝试使用

log_message('debug','values json2: '.json_encode($log_my_post));

答案 1 :(得分:0)

这有效:

$string='{"data":[{"BegRecNbr": 81, "RecFrag": [{"Fields": {"mA": [1406.205078125, 1914.948486328125], "mB": [1769.690673828125, 1816.0640869140625, 1692.6290283203125, 744.02020263671875]}, "RecNbr": 81, "TimeOfRec": [731495520, 0]}], "TableNbr": 3}, {"BegRecNbr": 82, "RecFrag": [{"Fields": {"mA": [1406.19384765625, 1915.2742919921875], "mB": [1768.99462890625, 1815.36767578125, 1692.615478515625, 744.01434326171875]}, "RecNbr": 82, "TimeOfRec": [731496480, 0]}], "TableNbr": 3, "NbrOfRecs": 1}]}';
print_r( json_decode($string,1));

尝试使用json_decode($ string,1)。 1表示返回数组而不是对象。

相关问题