开发者

Serialize json 2-dimensional array, send two arrays, or other?

I have to send a 2-dimensional array (along with several other variables) to PHP using jQuery.ajax(). I believe my options are:

  1. Serialize to json w开发者_运维技巧ith JSON-js
  2. Send both arrays as csv strings and recompile on the other side.

My questions are:

A. Is there anything wrong with option #2 if I'd prefer not to include another library for a small function? B. Are there other options besides options #1 and #2?

Thanks!


You can try :

JSON.stringify(array);

No extra library required.


I'm sure there are other options; there's always a million ways to skin a cat. But I'd suggest option #1. When you send it as a JSON string (using a library that is quite small and only has two methods), you can then decode it in PHP using json_decode. No fuss, no muss.


A. Is there anything wrong with option #2 if I'd prefer not to include another library for a small function?

You might have issues with escaping/unescaping some characters.

B. Are there other options besides options #1 and #2?

Surely there must be. But I'd go with JSON, it's the simplest and cleanest solution.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜