Como obter um valor do objeto gson por chave
Eu tenho tentado seguir junto com esta soluçãoComo encontrar o nome especificado e seu valor em JSON-string de Java?
No entanto, não parece fazer sentido.
Eu defino um novo objeto gson a partir de uma string:
Exemplo de string aqui:http://api.soundrop.fm/spaces/XJTt3mXTOZpvgmOc
public void convertToJson()
{
Gson gson = new Gson();
Object gsonContent = gson.fromJson( stringContent, RadioContent.class );
}
E, em seguida, tente e retorne um valor:
public Object getValue( String find )
{
return gsonContent.find;
}
Finalmente é chamado com:
public static void print( String find = "title" )
{
Object value = radioContent.getValue( find );
System.out.println( value );
}
No entanto, estou recebendo um erro:
java: cannot find symbol
symbol: variable find
location: variable gsonContent of type java.lang.Object
Classes completas: Classe principal:http://pastebin.com/v4LrZm6k Classe de rádio:http://pastebin.com/2BWwb6eD