I can not extract the data from the "text" object of a json, I need to do it in java

0

This is the json that I get from the Google Vision API, I need to extract the "text" Object from the "responses" array, it would be very helpful if I could extract that data.

{
"responses":[  
      { 
     "textAnnotations":[],
     "fullTextAnnotation":{
            "pages":[],
             "text":"texto a obtener"
                          }
      }
           ]
}
    
asked by Sebastin Leyva Chumpitaz 25.05.2018 в 18:43
source

1 answer

0

Just try to traverse the json with the name of the variable

json={
"responses":[  
      { 
     "textAnnotations":[],
     "fullTextAnnotation":{
            "pages":[],
             "text":"texto a obtener"
                          }
      }
           ]
};
console.log(json.responses[0].fullTextAnnotation.text)

Update

For JAVA you can use the library java-json.jar

package stackoverflow;

import org.json.JSONException;
import org.json.JSONObject;

public class StackOverflow {

    public static void main(String[] args) throws JSONException{

        JSONObject json = new JSONObject("{\"responses\":[  \n" +
                        "      { \n" +
                        "     \"textAnnotations\":[],\n" +
                        "     \"fullTextAnnotation\":{\n" +
                        "            \"pages\":[],\n" +
                        "             \"text\":\"texto a obtener\"\n" +
                        "                          }\n" +
                        "      }\n" +
                        "           ]\n" +
                        "}"); 
        System.out.println(json.getJSONArray("responses").getJSONObject(0).getJSONObject("fullTextAnnotation").get("text").toString());

    }

}
    
answered by 25.05.2018 / 19:22
source