简体   繁体   English

如何在 javascript 和 php 中解码和编码多维数组

[英]How to decode and encode a multidimensional array in javascript and php

I need to encode a three dimensional array in javascript, send it to a php script and decode it there.我需要在 javascript 中编码一个三维数组,将其发送到 php 脚本并在那里解码。 The Problem is, javascript outputs array, just as one sequence of integers, you can't see the dimensions.问题是,javascript 输出数组,就像一个整数序列,你看不到维度。 I tried to convert the array to json but couldn't find figure out how to do it.我试图将数组转换为 json 但不知道该怎么做。

Thanks for your help谢谢你的帮助

If you're making an ajax call, say using $.post, jQuery will automatically encode the data before it hits the PHP script you called.如果您正在进行 ajax 调用,例如使用 $.post,jQuery 将在数据到达您调用的 PHP 脚本之前自动对数据进行编码。 The size, scope, and complexity of the object doesn't matter. scope 的大小和 object 的复杂性无关紧要。

Find a way to serialize the array - JSON or something similar.找到一种序列化数组的方法 - JSON 或类似的东西。 It provides a format to convert objects and arrays to plain text and vice versa.它提供了一种将对象和 arrays 转换为纯文本的格式,反之亦然。

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

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