10
u/McGlockenshire Mar 28 '15
Not to defend this too much, but this was a common pattern before JSON was called JSON and it became trivial to call json_encode or even use Services_JSON from PEAR. On the other hand, if that code is less than five or six years old, there's no excuse. All of the code in our shitty codebase that does this is 10+ years old, and we haven't had enough round tuits to fix it yet. At least it's stupid instead of broken.
15
u/tyteen4a03 Mar 28 '15 edited Mar 28 '15
This codebase is from 2014. My company outsourced this project to another local company because of lack of personnel, and their code was beyond shitty. I only had to touch this because we're rewriting this in Go.
Sweet times.
2
u/RenaKunisaki Mar 28 '15
Looks like they wanted to output those fields and only those fields, and couldn't be arsed to put the field list in an array for some reason.
4
u/tyteen4a03 Mar 28 '15
The array passed into the function contains exactly these fields.
They were shitty coders.
20
1
u/sugar_free_haribo Mar 29 '15
This looks like a toString method for logging/debugging purposes. Could use json_encode, but this is really not that egregious. It's pretty much how Java developers generally implement a toString.
1
1
1
u/whoisearth Mar 28 '15
:( I have to do this with XML because I'm parsing data from a 3rd party application and without access to their code I have to mirror what they provide. Sometimes you gotta do it :(
4
u/tyteen4a03 Mar 28 '15
Can't you just throw it into SimpleXML?
4
u/whoisearth Mar 28 '15
custom xml that involves multiple nested elements from quite a few tables in a database. I probably could, if given the time, figure it properly using the django rest framework serializers but end of the day it was much easier for me to make a template and just pass the data into there. Ugly as sin, but it works :)
1
u/hak8or Apr 04 '15
Excluding the code contents it self, my god this looks so damn beautiful! What theme/IDE/color scheme is this?
Sublime, VIM, what?
2
1
1
u/flynnski Mar 29 '15
I've actually had to do something similar, because ColdFusion and (lack of) case sensitivity. I don't want to talk about it.
-7
u/rossisdead Mar 28 '15
Real men make giant screenshots of snippets of code.
8
94
u/Timbo_KZ Mar 28 '15
I don't get it.
Why bother hard-coding JSON, when you can simply send your array to JavaScript using this simple trick:
When the array is in JavaScript, simply
JSON.parse()andalert()it, then use JNA to take a screenshot of the screen and save the popup content into a text file using Java's nativeString.fromWindowsScreenshot.All that's left now is just reading text file's content using PHP, just keep in mind you'll have to set a timeout of 2 to 3 days if your user is using IE.