0

我从 RESTful 服务接收此响应并将其保存到 JSONObject:

{
    "GetCampaignsInProgressListResult": [
        108,
        162,
        171,
        103,
        185,
        147,
        218,
        16,
        67,
        226,
        44,
        // etc etc
    ]
}

上面的数据代表一个二进制数组。我正在尝试使用以下代码阅读它:

String rawResponse = client.getResponse();
JSONArray entries = null;
JSONObject o = new JSONObject(rawResponse);
entries = new JSONArray(o.getString("GetCampaignsInProgressListResult"));

我想访问二进制数据并将其保存到字节数组中,但由于它没有属性名称,我无法使用:

for (int i = 0; i < entriesLength; i++) {
    JSONObject entry = entries.getJSONObject(i);
    Object something = entry.getString("SomeTag");
}

如何访问二进制数组?

4

1 回答 1

4

试试这个:

    String rawResponse = client.getResponse();
    JSONArray entries = null;
    JSONObject o = new JSONObject(rawResponse);
    entries = new JSONArray(o.getString("GetCampaignsInProgressListResult"));
    byte[] bArr = new byte[entries.length()];
    for (int i = 0; i < entries.length(); i++) {
        bArr[i] = (byte) entries.getInt(i);
    }
于 2013-04-03T19:01:10.680 回答