json - How do I get the url of the image tag in Java? -
the imageurl is:
the jsonobject:
{ "type":"table", "subtype":"attribute_list", "doc":"https://api-v2.swissunihockey.ch/api/doc/attribute_list", "data":{ "context":null, "headers":[ { "text":"name", "key":"teamname", "long":"name", "short":"name", "prefer":"fit" }, { "text":"logo", "key":"logo_url", "long":"logo", "short":"logo", "prefer":"fit" }, { "text":"webseite", "key":"website_url", "long":"webseite", "short":"webseite", "prefer":"fit" }, { "text":"teamportrait", "key":"portrait", "long":"teamportrait", "short":"teamportrait", "prefer":"fit" }, { "text":"liga", "key":"liga", "long":"liga", "short":"liga", "prefer":"fit" }, { "text":"anschrift", "key":"address", "long":"anschrift", "short":"anschrift", "prefer":"fit" } ], "title":"mr krauchthal ii", "subtitle":null, "tabs":[ ], "slider":null, "regions":[ { "text":null, "rows":[ { "highlight":false, "cells":[ { "text":[ "mr krauchthal ii" ] }, { "image":{ "alt":"", "url":"https://res.cloudinary.com/swiss-unihockey/image/upload/t_club_logo/gin0rst7ocrcuioryacs.png" } }, { "url":{ "href":null, "text":"webseite" } }, { "image":{ "alt":"", "url":null } }, { "text":[ "4. liga" ] }, { "text":[ "mr krauchthal", "thomas" ] } ] } ] } ] } }
what need json parser. there several libraries can use jackson or gson.
here basic json handling gson:
jsonobject json = new jsonparser().parse(myjsonstring).getasjsonobject(); // parse string json , return jsonobject jsonobject data = json.get("data").getasjsonobject(); // returns jsonobject contains in "data":{...} jsonarray regions = data.get("regions").getasjsonarray(); // array "regions" for(int i=0;i<regions.size();i++){ // loop through array jsonobject region = regions.get(i).getasjsonobject(); // element in array (as jsonobject) string text= region.get("text").getasstring(); // jsonelement jsonobject , read string (like "text") }
it not seem "clean" or "easy" , other json libraries differently, recommend way if don't want whole "data" object parsed in pojo. have is, use methods showed walk through json until "url" or other element want.
Comments
Post a Comment