Mailing List Archive
tlug.jp Mailing List tlug archive tlug Mailing List Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][tlug] My first JSON object
- Date: Sat, 19 Jun 2010 12:02:32 +0900
- From: Dave M G <dave@example.com>
- Subject: [tlug] My first JSON object
- User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.9) Gecko/20100423 Thunderbird/3.0.4
TLUG,I'm trying to create my first JSON object, and I'm a bit fuzzy. I've managed to work out just about all the steps, except the last.Specifically, what I need to do is have Javascript running on the client create a JSON object, send that to the server, have PHP on the server accept that JSON and parse it to put into a MySQL database. Finally, the server needs to muck about with the data and send a revised JSON - pretty much the same data, but verified - back to the client.Note that I haven't actually tried implementing any of the steps below yet, as this time I'm trying to get a complete blueprint instead of doing what I usually do which is stumble around in the dark bumping into things.Okay, so, I think I can create a JSON in Javascript in the following manner. var myJSON = {"pet" = "dog", "car" = "hybrid"}; Cool. Nice and easy. Now I've got "myJSON" ready to go.JSONrequest = JSONRequest.post("http://myserver.com/jsonhandler.php", myJSON);On the server, jsonhandler.pho decodes the JSON object into a PHP array. $JSONarray = json_decode($_POST['myJSON']);Assuming I've succeeded in geting a PHP array built, then I'm in familiar ground, dealing with just PHP and MySQL. I take the PHP array and put data in the database, get new data from the database, and construct a new, revised array with appropriate updated values. Then I turn around and construct a JSON object from that new array.$JSONarrayRevised = json_encode($dataFromMySQL); Okay, now we hit where I'm fuzzy.I want to output that JSON data in such a way so that the client will pick it up.If I just output it, will the client be able to and parse that data? If so, how, exactly?I know that a number gets stored in that JSONrequest variable I created at the start. But I don't think that number is useful to me in this case... or is it?Can anyone help me get that last step of sending the PHP created JSON object to the client?-- Dave M G
- Follow-Ups:
- Re: [tlug] My first JSON object
- From: Mattia Dongili
Home | Main Index | Thread Index
- Prev by Date: Re: [tlug] [OT] What's up with online Japanese<->Japanese dictionaries?
- Next by Date: Re: [tlug] [OT] What's up with online Japanese<->Japanese dictionaries? [SOLVED]
- Previous by thread: [tlug] (test) please ignore me
- Next by thread: Re: [tlug] My first JSON object
- Index(es):
Home Page Mailing List Linux and Japan TLUG Members Links