Is there any simplest way to parse JSON from a URL? I used Gson I can't find any helpful examples.
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
Here is a easy method.
First parse the JSON from url -
Then place a task and then read the desired value from JSON -
You can then place a task like this -
I use java 1.8 with com.fasterxml.jackson.databind.ObjectMapper
Integer.class can be also a complex type. Just for example used.
A simple alternative solution:
Paste the URL into a json to csv converter
Open the CSV file in either Excel or Open Office
Use the spreadsheet tools to parse the data
GSON has a builder that takes a Reader object: fromJson(Reader json, Class classOfT).
This means you can create a Reader from a URL and then pass it to Gson to consume the stream and do the deserialisation.
Only three lines of relevant code.
First you need to download the URL (as text):
Then you need to parse it (and here you have some options).
GSON (full example):
Outputs:
Try the java API from json.org: