Jump to content
carlosguerradev

Java JSON: Erro de syntax

Recommended Posts

carlosguerradev

Boas tarde alguém me poderia ajudar com um erro de syntax ?

Eu queria adicionar + 1 get para obter a URL da foto do utilizador mas por algum motivo dá erro de syntax :/ diz que nao é string

Com o erro



Erro no ultimo get  "The method get(String) is undefined for the type String" (Eu sei o que está a dizer mas nao percebo o motivo :|)

public static String getUserPhoto() throws IOException, JSONException {
		JSONObject json = readJsonFromUrl("https://www.googleapis.com/youtube/v3/channels?part=snippet&id=UC-lHJZR3Gqxm24_Vd_AJ5Yw&key=AIzaSyCN3tzwYEp5oRrcvlzr505-rCo--PVZyY8");		
		return new JSONObject((new JSONObject(json.get("items").toString().replaceAll("^\\[|]$",""))).get("snippet").toString()).get("thumbnails").toString().get("thumbnails").toString();
		
	}

Sem o erro:

Este exemplo é sem o ultimo get que eu pus que é onde está a dar erro

public static String getUserPhoto() throws IOException, JSONException {
		JSONObject json = readJsonFromUrl("https://www.googleapis.com/youtube/v3/channels?part=snippet&id=UC-lHJZR3Gqxm24_Vd_AJ5Yw&key=AIzaSyCN3tzwYEp5oRrcvlzr505-rCo--PVZyY8");		
		return new JSONObject((new JSONObject(json.get("items").toString().replaceAll("^\\[|]$",""))).get("snippet").toString()).get("thumbnails").toString();
		
	}
	

 

Share this post


Link to post
Share on other sites
HappyHippyHippo

o teu erro está aqui : 

toString().get("thumbnails")

a classe String não tam a função get


IRC : sim, é algo que ainda existe >> #p@p

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.