简体   繁体   English

从PHP数组创建json_encode字符串

[英]Create a json_encode string from PHP array

I am sending an array from arduino to PHP using php_serial.class. 我正在使用php_serial.class从arduino发送数组到PHP。 This part is working fine. 这部分工作正常。 My PHP array will be in the following format 我的PHP数组将采用以下格式

$myArray{"EQ:24","YR15", "MTH: 2", "100 MPH",0,1,0,1,1,1,1,1}.

There are 12 values in the array. 数组中有12个值。 I am very new to working with php, jquery, and quite frankly programming. 我对使用php,jquery和坦率的编程非常陌生。 Can someone please point me in the right direction on how I can send this array from PHP to an html page. 有人可以向我指出正确的方向,说明如何将数组从PHP发送到html页面。 I am guessing json_encode would work good for this. 我猜json_encode为此可以很好地工作。 The text strings I want to update text boxes in jquery with and the 0's and 1's I want to update sliders states with. 我想用来更新jquery中的文本框的文本字符串以及我想用来更新滑块状态的0和1的文本字符串。

POST data is data that is handled server side. POST数据是在服务器端处理的数据。 And Javascript is on client side. Javascript位于客户端。 So there is no way you can read a post data using JavaScript in html page. 因此,您无法使用html页面中的JavaScript读取帖子数据。

you can call ajax request to php page and php page print a json or in any format data,so you can handle that data from your html page.you need to just print data in php file. 您可以调用ajax请求到php页面,并且php页面以json或任何格式打印数据,因此您可以从html页面处理该数据。您只需将数据打印在php文件中即可。

PHP PHP

$json_format = json_encode($array);
echo $json_format;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM