How to make a nested Json object in Java?

后端 未结 4 1972
伪装坚强ぢ
伪装坚强ぢ 2020-12-25 13:42

I want to program a nested JSON Object for my Android device, but how? I have only basic experience with Json, so I would appreciate if someone could help me with the follow

4条回答
  •  无人及你
    2020-12-25 14:16

    BasicNameValuePair is what you use to add POST parameters. it's a little unclear what you are asking. are you asking how, given that JSON, to submit the param values as post parameters?

    you need to first parse the JSON, then pull out the parameters, then add them to the form post, like this,

    JSONObject jo = new JSONObject(jsonString);
    JSONObject joParams = jo.getJSONObject("params");
    String username = joParams.getString("username");
    
    post.add(new BasicNameValuePair("username",username);
    

    you will of course want to do checking on the JSON to ensure the params object exists, and to ensure the username parameter exits.

提交回复
热议问题