Note that there are some explanatory texts on larger screens.

plurals
  1. POjava - json extract/decode issue - json within json?
    primarykey
    data
    text
    <p>very simple java/json question.</p> <p>I have the following test chunk of code. I can get the 1st element using the ".get()" by either index, or by the key. but I can't get any other elements by key...</p> <p>The test dies, with nothing on the cmdline.. I'm assuming this is due to something not being correctly set within my env to display err results..</p> <p>UPDATE:: OK.. it appears that the real issue is I don't know how to get an item, and to 1st determine what "type" it should be cast to. for the "nickname","name".. if I cast them as String.. I get the correct result.. </p> <p>So, how can one iterate through the key/value list of the json to determime how to correctly get each item??</p> <p>The test code is:</p> <pre><code>import org.json.simple.JSONObject; import org.json.simple.*; //import org.json.simple.JSONValue; public class asuH { public static void main(String[] args){ final String[] arguments = args; java.awt.EventQueue.invokeLater(new Runnable() { public void run() { try{ String json_=arguments[0]; //--get the page for the 1st and 2nd urls... //test the json input.. System.out.println("asdfsfd \n"); System.out.println(json_); //JSONObject obj=new JSONObject(); //Object obj=JSONValue.parse(json_); String k9="{\"nickname\":null,\"num\":100,\"contact\":{\"phone\":\"123456\",\"zip\":\"7890\"},\"balance\":1000.21,\"is_vip\":true,\"name\":\"foo\"}"; //JSONObject obj = (JSONObject)JSONValue.parse(json_); JSONObject obj = (JSONObject)JSONValue.parse(k9); System.out.print("11 \n"); String fa = (String)obj.get("nickname"); System.out.print(fa); System.out.print("22 \n"); fa = (String)obj.get("contact"); //&lt;&lt; not working!!! System.out.println("22 cc\n"); System.out.println(fa); String ttt=obj.toString(); System.out.print(ttt); System.out.println("\n s4354455 \n"); System.exit(0); } catch (Exception ex) {} System.exit(0); } }); } } </code></pre> <p>any thoughts/pointers are appreciated. </p> <p>thanks</p>
    singulars
    1. This table or related slice is empty.
    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. 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