Once you have the responseMap
, then you can get the name
of the location like this:
JSONObject jsonObject = (JSONObject)responseMap.get("location");
String name = String.valueOf(jsonObject.get("name"));
Вопрос
I have a GraphUserCallback that returns a graphObject of the requested user information, I think put this into a Map as below.
Map<String, Object> responseMap = new HashMap<String, Object>();
GraphObject graphObject = response.getGraphObject();
responseMap = graphObject.asMap();
I then grab each data item I need from the map e.g:
birthday = responseMap.get("birthday").toString();
This works well, apart from when I try to get the users location, the responseMap location item is actually an object containing name and id.
So I try to do
location = responseMap.get("location").get("name").toString();
However I get the error:
method get(String) is undefined for the type Object
What can I do to get the 'name' field from the object in the 'location' of the responseMap
I should not that the structure seems to be a JSON object as if I do
location = responseMap.get("location").toString();
I get what looks like a JSON
Решение
Once you have the responseMap
, then you can get the name
of the location like this:
JSONObject jsonObject = (JSONObject)responseMap.get("location");
String name = String.valueOf(jsonObject.get("name"));