JSON, URL-encode, and UTF-8

Peter W A Wood peterwawood at gmail.com
Thu Aug 20 20:58:12 EDT 2015


Jacque

> On 21 Aug 2015, at 07:35, J. Landman Gay <jacque at hyperactivesw.com> wrote:
> 
> Right. Works without header in 6, fails in 7. Thanks for looking at my file. I wonder what would happen if I use the LC 6 libURL script in LC 7. Will my unicode go all wonky? The file I sent you is in English but most of the time it won't be.

I ran a very simple test using the message box and a very simple PHP script. I was able to post json={JSON} to PHP and get it back.

In the message box (using LC 7..0.3)

post textEncode("json={" & quote & "é" & quote & ": 1}", "UTF-8") to  URL "http://Localhost/jacque.php"
put textDecode(it, "UTF-8”)

The PHP script:

<?php 
  echo($_POST["json"]);
?>

The result in the message box:

{"é": 1}

This would indicate your issue is not caused by a bug.

I’m not sure if you are URLEncoding the data … that certainly seems to cause a problem

Revised LiveCode
put textEncode("{ " & quote & "é" & quote & ": 1}", "UTF-8") into tJSON
put "json=" before tJSON
post URLEncode(tJSON) to URL "http://Localhost/jacque.php"
put textDecode(it, "UTF-8”)

Result 
PHP sends back an empty response.

Hope this is of some help.

Peter


More information about the use-livecode mailing list