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] Something's not right about my JSON
- Date: Sat, 14 Aug 2010 20:11:40 +0900
- From: Dave M G <dave@example.com>
- Subject: [tlug] Something's not right about my JSON
- User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.11) Gecko/20100713 Thunderbird/3.0.6
TLUG,I've got some Javascript code that creates a JSON string out of a Javascript array, then passes it to a PHP script, which in turn makes it a PHP array.Or, at least, I almost have that. I'm not getting the results I'm hoping for, and I think it's because I'm just a little confused about how I'm nesting my arrays.The goal is to create a nested array that looks something like this: { loginData : { "email" : "some@example.com" "password" : a1oirngdf09unsvlsd90" } "newUserData" : "No" } I hope I have the syntax for that right.I've tried creating this JSON sting using the following code (edited a bit for brevity - hopefully no typos/syntax errors):var loginData=new Array(); loginData.email=document.getElementById('email').value; loginData.password=$.md5(document.getElementById('password').value); userData=new Array(); userData.login=loginData; userData.newUserData="No"; jsonString = JSON.stringify(userData); $.post('jsonhandler.php', {JSON: jsonString}, checkResult, "json"); Then on the PHP side, I extract the data I want like so: $array = json_decode(stripslashes($_POST['JSON']), true);if (myFunctionThatChecksLoginAndReturnsTrueOrFalse($karray['userData']['email'],$array['userData']['password']))I think I'm close in the code, but the the array is not constructed properly at some stage.For one thing, when I output the value of the stringified userData and look at it in Firebug, it simply shows me: [] Can someone point out where I'm going wrong? Any advice would be much appreciated. -- Dave M G
- Follow-Ups:
- Re: [tlug] Something's not right about my JSON
- From: Pier Fumagalli
Home | Main Index | Thread Index
- Prev by Date: Re: [tlug] bash and grep and diff
- Next by Date: Re: [tlug] Something's not right about my JSON
- Previous by thread: [tlug] QA/Tester position - Tokyo - 6-8Mjpy/yr
- Next by thread: Re: [tlug] Something's not right about my JSON
- Index(es):
Home Page Mailing List Linux and Japan TLUG Members Links