Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Parse your response JSON as a JSONObject, then get another JSONObject for the "name" key, if it throws a JSONException then your object is probably a String in with case you can call get String for the "name" key in your catch block. </p> <pre><code>String name = ""; JSONObject serverJSON = new JSONObject(YOUR_JSON_RESPONSE_STRING_FROM_SERVER); try { JSONObject nameObject = serverJSON.getJSONObject("name"); if (nameObject.has("first_name")) { name = nameObject.getString("first_name") + " "; } if (nameObject.has("middle_name")) { name += nameObject.getString("middle_name") + " "; } if (nameObject.has("last_name")) { name += nameObject.getString("last_name"); } name = name.trim(); } catch (JSONException e) { // Probably a String, try again... try { name = serverJSON.getString("name"); catch (JSONException e) { // Not a String or a JSONObject... figure out what's wrong... e.printStackTrace(); } } </code></pre> <p>I would really recommend though, that if you have any control of the server that you make sure that the name key choose one type and sticks to it; a JSONObject... You would be able to use the has(String key) member function in if statements to properly find all of your data without knowing what existed at runtime...</p> <p>EDIT: Thought of a different idea... Parse the String to the first colon and see if the next non-whitespace character is a quotation mark, if it is, then your key belongs to a String, if it is a curly brace then it's a JSONObject. (If neither, then you have an error, because you aren't expecting an array or number or null or anything else...)</p> <pre><code>boolean jsonIsString = true; String searchString = json.substring(json.indexOf(":")).trim(); if ("{".equals(searchString.charAt(0)) { jsonIsString = false; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload