我想通过url与android检索json数据

时间:2010-11-08 18:10:53

标签: android json http url

我正在开发一个API,我想把这个地址中显示的json数据显示在这样的地址:https://api.empireavenue.com/profile/info/?apikey=YOURAPIKEY&username=TICKER&password=PASSWORD

并将此数据显示在我的应用上。 感谢。

1 个答案:

答案 0 :(得分:0)

parseJson方法的输入应该是从HTTP请求返回的任何内容。这也假定格式如下:

{ “rootKey”:{ “INTVAL”:1}}

您必须根据结构修改查询对象的顺序。


private static final ROOT_JSON_KEY = "rootKey";
private static final INT_VALUE_NAME = "intVal"; 

public void parseJson(String webServiceResponse) {

    JSONObject json = new JSONObject(webServiceResponse);
    JSONObject rootObject = json.getJSONObject(ROOT_KEY);
    int intValues = rootObject.getInt(INT_VALUE_NAME);

}

编辑:抱歉,编码错误。