1

jsonファイルからバイト[]を解析するのを手伝ってくれる人はいますか-

JSON ファイルは次のようになります。

    {
    name:"test"
    myImage:[67,78,....]
    }

このファイルには複数の画像が含まれる可能性があり、システムのメモリが不足する可能性があるため、新しい JSONObject() を作成して解析したくありません。

GSON/Jackson/JSONReader(android>3.1)を使いたいのですが、ほとんどがgetInt()、getString()オブジェクトを持っているようです。

byte[] 自体を解析して、後で描画可能オブジェクトに変換できるオブジェクトにするにはどうすればよいですか。

どんな助けでも本当に感謝しています。

4

3 に答える 3

0

What have you tried? In Jackson, you could use a POJO like:

class Stuff {
  public String name;
  public byte[] myImage;
}

Stuff stuff = new ObjectMapper().readValue(new File("stuff.json"), Stuff.class);

which should work.

But this JSON serialization is not the typical way to do it: it is more common to include byte array as base64 encoded data. This is how Jackson will serialize it as, if you use ObjectMapper.writeValue(...). The reason is that base64 encoding will be more compact, use less memory than number arrays.

于 2012-04-05T14:07:32.357 に答える
0

私はこの方法で解決しました

InputStream instream = entity.getContent();
            Gson gson = new Gson();
            Reader reader = new InputStreamReader(instream);
            JsonReader jsonReader = new JsonReader(jsonReader);
                jsonReader.beginArray();
                while (jsonReader.hasNext()) {
                    MyCustomObject cobj = gson.fromJson(jReader,
                            MyCustomObject.class);
                    byte[] image = cobj.Image;
                    }
于 2012-04-07T18:18:04.307 に答える
0

JSONObject->getString().getBytes();

GSON/JsonReader->getString().getBytes();

于 2014-02-13T22:11:00.277 に答える