Win a copy of Machine Learning with R: Expert techniques for predictive modeling this week in the Artificial Intelligence and Machine Learning forum!
  • 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
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

Help with parsing this JSON

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have the following JSON (its a much bigger file)... and I keep getting that kick2 cannot be found.

JSON


JAVA
The first System.out.println will print.


Thanks!
 
Johnathon Anderson
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On a side note...if I do...



It will print out:

[{"kick":"0.2"},{"kick2":"0.2"}]
[{"kick":"0.2"},{"kick2":"0.2"}]
 
Saloon Keeper
Posts: 21139
134
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You didn't say what you are trying to execute when you get the error.

In JavaBeans notation, the absolute path for the first kick2 value would be kickers_common[0].level1[0]["kick2"]

Note that level1 is an ARRAY of dictionary, not a dictionary. More commonly I'd expect the format to be:


That is, without the array.
 
Johnathon Anderson
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Tim Holloway wrote:You didn't say what you are trying to execute when you get the error.



I said that console tells me that kick2 cant be found. That was the error.
Yes, I can do it without an array inside of an array I guess. I just perfer iterating through the array. saves on code.
 
Tim Holloway
Saloon Keeper
Posts: 21139
134
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I rather doubt that that code gives that message. More likely it fails and dumps a stacktrace.

Anyway, your innermost loop is looking on its first pass for:

kickers_common[0].level1[0]["kick1"]
kickers_common[0].level1[0]["kick2"]

But level1[0] contains a dictionary with ONLY kick1 in it. The dictionary containing kick2 is in level1[1]! And level1[1] does not have a "kick1" in it. Each dictionary in the array as it is presently formatted has one and only one entry in it.
 
On top of spaghetti all covered in cheese, there was this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!