• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Bear Bibeault
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • salvin francis
  • Stephan van Hulst
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Jj Roberts

Better format for JSON structure?

 
Rancher
Posts: 522
7
Android Tomcat Server Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is the json structure returned by backend team.

I need to pass the abc to server if I select ABC, does this make sense?
Normally we are passing the value (ABC) to server no?

I feel like this json need to restructure again, which should look like below:
I not too sure because I more on front-end. Do you guys feel the same?

 
Saloon Keeper
Posts: 12493
269
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe your example will become more clear if you use real property names instead of "abc". Also, to me it doesn't make sense that a property named "companies" has an object value instead of an array. Can you verify that the response you get from the backend contains a property named "companies" that contains an object value?

I understand that in your front-end, given an object containing some properties, you want to send a request to the back-end that as the value of an "id" property, you want to use the key of the property from your original response. This is not conventional, but also not completely unheard of. It does imply to me that the application is not well designed though.

Can you tell us some more about the purpose of the application? That is, the original JSON is a response to a request for what exactly? And why do you need to select a specific property? What will you do with the specific property after you have selected it? Why?
 
Randy Tong
Rancher
Posts: 522
7
Android Tomcat Server Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Stephan,

Yes, it should returned as Array. The back-end team has restructured the Json.

Now they return as this

Shouldn't it be like this ?

I'm confused.
 
Rancher
Posts: 4743
50
  • Likes 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It should be:

The first version (theirs) has a single object in an array, which is incorrect. You want an array of companies.
The second version (yours) is invalid json. It doesn't need the repeat of the company name as a tag.
 
Stephan van Hulst
Saloon Keeper
Posts: 12493
269
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Agree with Dave.
 
Randy Tong
Rancher
Posts: 522
7
Android Tomcat Server Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks
 
Randy Tong
Rancher
Posts: 522
7
Android Tomcat Server Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wonder how could I loop through the levels list to get all the items if need written in dart language?


Json

I guess it should be this?
 
Stephan van Hulst
Saloon Keeper
Posts: 12493
269
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The first JSON you posted is valid, but doesn't make sense and is hard to work with. It's like you put a dictionary as the only element into a list.

The second JSON is much better, you actually have a list of levels. But what's the point of having both an "id" property and a "level_no" property if they're always going to have the same value? Just remove one of the two.

I don't understand your question. Are you asking us how to iterate a JSON array in the Dart language? First step is always to parse the JSON before you do any iterating.
 
Randy Tong
Rancher
Posts: 522
7
Android Tomcat Server Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have asked the backend team to return the second JSON to me since it more easier to get, but I still interested to know how to iterate the first JSON. I did parse the JSON.
DataResponse



 
Stephan van Hulst
Saloon Keeper
Posts: 12493
269
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well what does the Levels class look like?
 
Randy Tong
Rancher
Posts: 522
7
Android Tomcat Server Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Stephan van Hulst
Saloon Keeper
Posts: 12493
269
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah well it looks like your model does not reflect the JSON you want to parse. You model looks like the second JSON snippet that you want the back-end team to send you.
 
Randy Tong
Rancher
Posts: 522
7
Android Tomcat Server Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because I don't know how to parse the first JSON. Seems like I need to create object "1", "2" and "3" ?
 
Stephan van Hulst
Saloon Keeper
Posts: 12493
269
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your Levels class holds a levelNo, but going by the JSON you received it should instead hold a Map<String, Level>, with Level being a separate class that has an id and a levelNo property.
 
Do not meddle in the affairs of dragons - for you are crunchy and good with ketchup. Crunchy tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic