duanlu7223 2015-03-07 08:27
浏览 48

通过JSON将数组从php传递到Java(android)

I need to know how to pass an array from php to java. I can do the opposite thing: passing an array from java to php, but I dont know how to do the opposite. The code that i wrote is that:

`//php script
$response["success"] = 1;
$Id = {"1", "2"};
$response["Id"] = $Id;
echo json_encode($response);
`

//in java
int success = json.getInt("success");

ArrayList <Integer> Id = new ArrayList <Integer> ();
JSONArray jsonArray = json.getJSONArray("Id");
                if (jsonArray != null) { 
                       int len = jsonArray.length();
                       for (int i=0;i<len;i++){ 
                        Id.add(jsonArray.getInt(i));
                       } 
                    }

On my script I pass several things to my android app, and I'm using the same json object to pass them. Should I use different json objects, one for some things and another for the array using a jsonarray? (the tag "success" is passed with no issues).

the only error I get is this: sendUserActionEvent() mView == null But I think is something about the layout, so no matter with the question.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥100 Jenkins自动化部署—悬赏100元
    • ¥15 关于#python#的问题:求帮写python代码
    • ¥20 MATLAB画图图形出现上下震荡的线条
    • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
    • ¥15 perl MISA分析p3_in脚本出错
    • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
    • ¥15 ubuntu虚拟机打包apk错误
    • ¥199 rust编程架构设计的方案 有偿
    • ¥15 回答4f系统的像差计算
    • ¥15 java如何提取出pdf里的文字?