• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Help with parsing this JSON

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 27885
198
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 27885
198
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic