473,414 Members | 1,951 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

JSON Format - trouble using it for data interchange

nathj
938 Expert 512MB
Hi everyone,

I am currently working on a project where data is being passed from the cilent side to the server side quite a lot. I thought that AJAX and JSON would be perfect for this. I have written a small function to generate what I thought was JSON data:
Expand|Select|Wrap|Line Numbers
  1. function generateJSON(pcIDList)
  2. {
  3.     // set the default return
  4.     lcReturn = "" ;
  5.  
  6.     lcJSONString = '{';    
  7.     if (pcObjectName != "" && pcIDList != "")
  8.     {
  9.         // take the data into a JSON structure                                          
  10.         laIDList = pcIDList.split(",");
  11.         for(lnPntr in laIDList)
  12.         {
  13.             lcElementID    = laIDList[lnPntr] ;                                 
  14.             lcElement    = document.getElementById(lcElementID) ; 
  15.             lcJSONString += lcElement.name + ':' + lcElement.value  ; 
  16.             if(lnPntr < (laIDList.length - 1))
  17.             {
  18.                 lcJSONString += ',' ;
  19.             }
  20.         }
  21.  
  22.         lcJSONString += '}'    ;
  23.         lcReturn = lcJSONString ;
  24.     }
  25.  
  26.     return lcReturn ;
  27. }
  28.  
The parameter pcIDList is a comma separated list of from control ID's. So if I pass in:
Expand|Select|Wrap|Line Numbers
  1. 'dataQuantity,sameGroup,groupNumber'
  2.  
from a form where I have asked for 5 sets of data all in group 6 the output is:
Expand|Select|Wrap|Line Numbers
  1.     {dataQuantity:1,sameGroup:false,groupSelect:2}
  2.  
I'm not sure this is correct, but all my reading around on the subject has left me rather confused, so I'm seeking help. The final part of my current problem is how then to pass this data set from my JavaScript to my PHP so that it can be parsed correctly and used to control the process flow and eventually update the database.

Many thanks
nathj
Nov 22 '07 #1
3 1334
acoder
16,027 Expert Mod 8TB
Should that be groupNumber or groupSelect?

Why not just pass a string and let PHP parse the JSON?
Nov 27 '07 #2
nathj
938 Expert 512MB
Should that be groupNumber or groupSelect?
They should both be groupSelect
Why not just pass a string and let PHP parse the JSON?
Hi acoder,

This is waht I am trying to do, generate a string of data that is JSON formatted so that PHP can parse it for me. the plane was then to send the string as part of the query string to the php file.

However, the output I generate doesn't parse with json_decode(). I have tried it with true and false as the second parameter but alas the results is null.

Do you ave any suggestions on how to generate the JSON formatted string so that I can pass it to the PHP file for processing?

Many thanks
nathj
Nov 28 '07 #3
gits
5,390 Expert Mod 4TB
hi ...

i'm not quite sure but try to send it the following way, i think i remeber that encode always delivers it as an array so i assume decode expects an array too?

Expand|Select|Wrap|Line Numbers
  1. [{dataQuantity:1,sameGroup:false,groupSelect:2}]
kind regards
Nov 28 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: George Jempty | last post by:
In my journal anyway: "JSON: Javascript Unusable by the Client" http://slashdot.org/~scriptify/journal/103074
16
by: G Matthew J | last post by:
http://htmatters.net/htm/1/2005/07/evaling-JSON.cfm This is more or less in response to Mr Crockford's admonition a few months ago, "fork if you must". Ironically, although in that usenet post...
20
by: Luke Matuszewski | last post by:
Welcome As suggested i looked into JSON project and was amazed but... What about cyclical data structures - anybody was faced it in some project ? Is there any satisactional recomendation... ...
2
by: ChrisO | last post by:
I've been pretty infatuated with JSON for some time now since "discovering" it a while back. (It's been there all along in JavaScript, but it was just never "noticed" or used by most until...
6
by: dd | last post by:
I'm writing something in JS using the latest OO and JSON and I'm looking for a bit of guidance. I'm going to have this large object which has many top-level properties and some top-level...
3
by: xhe | last post by:
I found Jason is a very handy data format for client/server communication. But I just met a problem as follows: I want to read the data replied from server in Jason format, the reply is like...
2
by: vunet | last post by:
When implementing JSON as a form of data exchange between server and client, what security measures do I need to consider? For example, I have XMLHttpRequest returning JSON text from the server and...
0
by: crocodilu2008 | last post by:
JSON vs. XML JSON and XML are basically used for the same purpose—to represent and interchange data. I'll try to show you why you might want to use JSON rather than XML in an AJAX context by showing...
0
by: JonTwend | last post by:
I am working with the Twitter API and finding it great fun and generally easy to use. But I am having trouble getting to the data in the trends/current.json file. I am able to loop through the...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.