How to get String from JSONObject without Specific Name

后端 未结 2 2018
走了就别回头了
走了就别回头了 2020-12-31 20:20

Please check this code sample.

HttpEntity getResponseEntity = getResponse.getEntity();

String message = EntityUtils.toString(getResponseEntity,\"UTF-8\");

         


        
相关标签:
2条回答
  • 2020-12-31 21:09

    You can get values of json object like this without knowing key

    Iterator<String> keys= object.keys();
    while (keys.hasNext()) 
    {
            String keyValue = (String)keys.next();
            String valueString = object.getString(keyValue);
    }
    
    0 讨论(0)
  • 2020-12-31 21:20

    This should work.

    JSONObject object = new JSONObject(message);
    String objectString = object.getString(object.names().get(0)); 
    

    But it will only work if you sure that NextTransactionUrl node exists. By the way, in this case, this node could have another name, it will still work.

    0 讨论(0)
提交回复
热议问题