JSON encoding multi-dimensional arrays

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
GeoffreyB
Forum Newbie
Posts: 2
Joined: Wed Jun 09, 2010 7:28 pm

JSON encoding multi-dimensional arrays

Post by GeoffreyB »

I am writing an PHP web application which is to accept data from a desktop application process it and return a result set.
As this process will be happening at very regular interval and the speed of transmit-process-transmit process is vital I have chosen to use JSON encoding of data to keep it lightweight.
What I need to send is in the form of multi-dimensional arrays
The issue that I am having is with my testing. To emulate the desktop application I create the multi-dimensional array in PHP, encode it with the json_encode function and send it to the server to be processed. As I was not getting the results I expected I echoed and var_dumped at different stages in the process.
Straight after the json_encode I echo a perfectly formed json object but when I echo it after retrieving from $_REQUEST on the server the json object is only part there.

Code: Select all

Before

[{"contenderid":1,"CareerStarts":"7","API":"10523","AvSP":"2.30","CavSP":"2.45","#AvSP":"2.35","#CavSP":"2.50","SP1":"2.45","SP2":"2.50","SP3":"2.55","OP1":"6.00","OP2":"5.60","OP3":"7.80","CurrentBF":"1.95","CurrentNSW":"2.10","CurrentUNI":"2.65","CurrentVic":"1.90","SPBracket":"1","Delta":"0.65","Lean":"+9","Lean+":"10.35","Lean++":"12.24","GDSLean":"3.0","ZeroRank":"1","ZeroSPStats":"","FocusFrameChange":"","FocusFrameRecent":"","FocusFrameStars":"2","FocusFrameSum":"","BDGConsectutiveYellow":"3","BDGPercentageDrop":"28","BDG_BFUnderTote":"5","BDGYellowCount":"4","AvWWD":"52.5","WgtCh":"1.5","Wgt":"51","A":"3","X3":"","X4":"","Z":"","C#":"","G#":""},{"contenderid":2,"CareerStarts":"10","API":"15793","AvSP":"2.75","CavSP":"2.70","#AvSP":"2.75","#CavSP":"2.70","SP1":"2.45","SP2":"2.60","SP3":"2.90","OP1":"6.00","OP2":"5.60","OP3":"7.80","CurrentBF":"3.20","CurrentNSW":"3.00","CurrentUNI":"3.65","CurrentVic":"2.90","SPBracket":"1","Delta":"0.98","Lean":"+13","Lean+":"12.90","Lean++":"14.73","GDSLean":"4.0","ZeroRank":"2","ZeroSPStats":"","FocusFrameChange":"","FocusFrameRecent":"","FocusFrameStars":"2","FocusFrameSum":"","BDGConsectutiveYellow":"3","BDGPercentageDrop":"28","BDG_BFUnderTote":"5","BDGYellowCount":"4","AvWWD":"0.5","WgtCh":"0.5","Wgt":"54","A":"4","X3":"","X4":"","Z":"","C#":"","G#":""}]


After
[{"contenderid":1,"CareerStarts":"7","API":"10523","AvSP":"2.30","CavSP":"2.45","
Is there any suggestions to what is going wrong here. Why is the json object string being truncated?
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: JSON encoding multi-dimensional arrays

Post by Eran »

If you're receiving it from the address line you need the number sign # to be URL encoded
GeoffreyB
Forum Newbie
Posts: 2
Joined: Wed Jun 09, 2010 7:28 pm

Re: JSON encoding multi-dimensional arrays

Post by GeoffreyB »

thanks I'll do that and give it a go
Post Reply