Skip to content
Advertisement

Parse a String java

I have a BuilderString that contain the same result as in this link: https://hadoop.apache.org/docs/current/hadoop-project-dist/

I’m looking to extract the values of the “. And return a list of String that contain all the files name.

My code is:

JavaScript

How can I parse JSON to take all the values of pathSuffix and return a list of string that contains the file names ? Could you please give me a suggestion ? Thanks

Advertisement

Answer

The good option

Do the following steps:

  1. Convert to JSON
  2. Get the value using: JSONObject.get("FileStatuses").getAsJson().get("FileStatus").getAsJsonArray()
  3. Iterate over all objects in the array to get the value you want

The bad option

Although as mentioned it is not recommended- If you want to stay with Strings you can use:

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement