JSONArray
Hi guys,
I am getting the following error when I am trying to run the code in the pastebin link and I dont really understand why as I copied from a doc which worked on the video.... https://pastebin.com/hGiZ1gz0
Halwp
Pastebin
dc - Pastebin.com
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
44 Replies
⌛
This post has been reserved for your question.
Hey @netty.bootstrap! Please useTIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here./close
or theClose Post
button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
Also, if anyone has a better idea to read out of a json file, let me know!
ah well, it says you're trying to get an object when it's an array
soooooooo
what does the source look like?
Uh what source do you mean
I sent a pastebin
Apparently you have an object in your json file, but you have code that expects an array.
Yeah this is a thing of json-simple
If you have a
{}
, you need to cast to JSONObject
, not JSONArray
at that position
Also it may be better to use json-java instead of json-simple
json-simple is a bit questionable
or you could use an object mapperok can you send an example
Maybe read about JSON before tackling this project?
of what exactly?
usage of json java or json java in general
Can you show your JSON?
btw in your code, the line
JSONArray dbList = (JSONArray) obj;
is likely the issueWait, you learn from a video of someone who writes code like this?
that's how json-simple works
and why I wouldn't use it
or Gson, I kinda like their object model
Nah, it has
getString
. And nothing explains that double cast.it is json-simple, not json-java
https://javadoc.io/doc/com.googlecode.json-simple/json-simple/latest/index.html
yup
So that's not an array. What do you mean, "it worked on the video"?
erm idk
That looks... very crude.
You... Don't know what you meant? It's like when you add random words in a sentence, Que sera sera, you don't know what it means it's just for style?
Dude its obvious what I meant by the question I asked
What it obviously means is that you watched a video of a guy who lied and was saying that given some files, trying to run the entire project doesn't fail in the same way yours fail
So unless you want to tell me that what it meant isn't the obvious...
What? My question was, how I can read values out of a json file I have never used that package before so how would I know its not working when you are using an array for an object
And my question was, what do you mean it worked on the video?
well he had the code in his main method and the config and it worked
There's nothing that looks like an array in that JSON file.
I can tell that too
And you ensured you have the same code everywhere. So, fundamentally, you watched a video of a guy lying?
Frustratingly enough I have not yet found a JSON library I like. I make mine for whenever I use JSON for personal purpose.
I don't know, Gson is pretty good. Although I usually use Jackson for a sole reason that it's usually already in dependencies.
yeah, I just wish gson was split
That all the reflection based stuff was a separate library
I have checked and tried a few now but still could not find any good libary to do what I wanna do
Might just stick with vertx
vertx is slaying a mosquito with an elephant
if you want one that works similar to json-simple (i.e you tell it what to access), you can use json-java:
if you want something that converts between JSON and your objects automatically, use gson or jackson
ok ill try
Ok so I managed to (kinda) do what I wanna do now with vertx, but now is my question... how do I access specific values or strings now, which are returned? Code I used:
Lol, vert.x has its own JSON parser?
yu
It works fire and vertx is a very good libary at all
Anyway, something like
jsonObj.getJsonObject("database").getString("SERVER_IP")
should work.ahhh omg i am dumb
obv
ill try tomorrow doe, thanks mate
looks like a json-java wrapper or repackaging
Using vertx is completely wrong for this, unless you're already using as a webserver
💤
Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use /help ping
.
Warning: abusing this will result in moderative actions taken against you.