I’m writing an Android app where I’m trying to get the #text string from a JSON that looks like this
{
"recenttracks": {
"track": {
"artist": {
"#text": "Jeremy Fisher",
"mbid": "7be30286-3510-4bc4-a587-51d9ad7c2b47"
...
But because of the hash tag I get nothing in return:
Error parsing data org.json.JSONException: No value for
Replacing #text with mbid works fine. Code:
try{
JSONObject container = new JSONObject(readLastFMFeed);
JSONObject recenttracks = container.getJSONObject("recenttracks");
JSONObject track = recenttracks.getJSONObject("track");
JSONObject artist = track.getJSONObject("artist");
String sArtist = track.getString("#text");
Toast.makeText(LoggedIn.this, sArtist, Toast.LENGTH_LONG).show();
}catch(JSONException e){
Log.e("log_tag", " Error parsing data "+e.toString());
}
How can I escape the hash tag?
You don’t need to escape it. You just made a little silly mistake. Instead of:
Write: