Click here to Skip to main content
15,896,912 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralRe: JSON responses -- what's your preference? Pin
Marc Clifton3-Apr-19 2:52
mvaMarc Clifton3-Apr-19 2:52 
AnswerRe: JSON responses -- what's your preference? Pin
Nish Nishant3-Apr-19 2:53
sitebuilderNish Nishant3-Apr-19 2:53 
AnswerRe: JSON responses -- what's your preference? Pin
megaadam3-Apr-19 3:16
professionalmegaadam3-Apr-19 3:16 
AnswerRe: JSON responses -- what's your preference? Pin
Mike Hankey3-Apr-19 3:24
mveMike Hankey3-Apr-19 3:24 
AnswerRe: JSON responses -- what's your preference? Pin
GuyThiebaut3-Apr-19 3:29
professionalGuyThiebaut3-Apr-19 3:29 
GeneralRe: JSON responses -- what's your preference? Pin
Marc Clifton3-Apr-19 4:13
mvaMarc Clifton3-Apr-19 4:13 
GeneralRe: JSON responses -- what's your preference? Pin
Scott Serl3-Apr-19 6:24
Scott Serl3-Apr-19 6:24 
GeneralRe: JSON responses -- what's your preference? Pin
bence983-Apr-19 22:33
bence983-Apr-19 22:33 
I also thought that a valid JSON document has to have a root object. Is it not the case then?
Anyways, I prefer the first one because it's shorter, and since it is a response, you should already well know what's gonna be in it: exactly the data requested.
However, I have had some issues with the Java JSON library being unable to parse arrays by themselves. As a result, the way it's implemented in production right now (as suggested by StackOverflow :P ) is as follows:
  • JSON comes in on the network, looking like the first example you gave
  • Function checks if it starts with '[' and finds that yes, it does
  • So it appends some string around the received text, making it look like the second one
  • JSON lib parses this. The returned JsonObject's only JsonArray member is saved, the rest discarded
  • Prod code gets this JsonArray back to do whatever
Fun times!

"I don't think about dying. It is the last thing I want to do. " - theoldfool
AnswerRe: JSON responses -- what's your preference? Pin
User 48350473-Apr-19 3:48
User 48350473-Apr-19 3:48 
AnswerRe: JSON responses -- what's your preference? Pin
#realJSOP3-Apr-19 4:00
professional#realJSOP3-Apr-19 4:00 
GeneralRe: JSON responses -- what's your preference? Pin
Marc Clifton3-Apr-19 4:15
mvaMarc Clifton3-Apr-19 4:15 
GeneralRe: JSON responses -- what's your preference? Pin
#realJSOP3-Apr-19 4:20
professional#realJSOP3-Apr-19 4:20 
GeneralRe: JSON responses -- what's your preference? Pin
dandy723-Apr-19 10:21
dandy723-Apr-19 10:21 
AnswerRe: JSON responses -- what's your preference? Pin
User 48350473-Apr-19 4:10
User 48350473-Apr-19 4:10 
AnswerRe: JSON responses -- what's your preference? Pin
dan!sh 3-Apr-19 4:27
professional dan!sh 3-Apr-19 4:27 
AnswerRe: JSON responses -- what's your preference? Pin
Richard Deeming3-Apr-19 8:15
mveRichard Deeming3-Apr-19 8:15 
AnswerRe: JSON responses -- what's your preference? Pin
Chris Maunder3-Apr-19 9:17
cofounderChris Maunder3-Apr-19 9:17 
AnswerRe: JSON responses -- what's your preference? Pin
dandy723-Apr-19 10:19
dandy723-Apr-19 10:19 
QuestionRe: JSON responses -- what's your preference? Pin
Super Lloyd3-Apr-19 13:51
Super Lloyd3-Apr-19 13:51 
AnswerRe: JSON responses -- what's your preference? Pin
agolddog4-Apr-19 2:45
agolddog4-Apr-19 2:45 
AnswerRe: JSON responses -- what's your preference? Pin
Kirk 103898214-Apr-19 4:25
Kirk 103898214-Apr-19 4:25 
AnswerRe: JSON responses -- what's your preference? Pin
Gerry Schmitz4-Apr-19 13:06
mveGerry Schmitz4-Apr-19 13:06 
AnswerRe: JSON responses -- what's your preference? Pin
paheal4-Apr-19 19:44
professionalpaheal4-Apr-19 19:44 
AnswerRe: JSON responses -- what's your preference? Pin
maze34-Apr-19 22:47
professionalmaze34-Apr-19 22:47 
AnswerRe: JSON responses -- what's your preference? Pin
thewazz8-Sep-19 9:39
professionalthewazz8-Sep-19 9:39 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.