Android 2.1中JSONObject的Base64解码

时间:2022-11-03 18:34:26

I need to decode JSONObject in Android 2.1 with Base64.I know that Base64 class supports Android 2.2+,that's why I include the source code in my project.So I need to do something like that :

我需要在Android 2.1中用Base64解码JSONObject。我知道Base64类支持Android 2.2+,这就是我在项目中包含源代码的原因。所以我需要这样做:

JSONObject clientHash = new JSONObject();
byte[] tmpSecData = Base64.decode(clientHash.getJSONObject("client_auth_hash"));

Any suggestions how to do that or is it possible?

有什么建议吗?

1 个解决方案

#1


2  

Lets try it,

让我们试一试,

  1. Convert the clientHash.getJSONObject("client_auth_hash") in String then byteArray,
  2. 将clienthass . getjsonobject(“client_auth_hash”)转换为字符串,然后是byteArray,
  3. then use,

    然后使用,

    byte temp[];
    Base64 b = new Base64();
    String jsonString = clientHash.getJSONObject("client_auth_hash").toString();
    temp = b.decode(jsonString.getBytes());
    
  4. then use your temp byte[].

    然后使用您的临时字节[]。

Hope this will help you. If its work then inform me. Thanx.

希望这能对你有所帮助。如果它的工作通知我。谢谢。

#1


2  

Lets try it,

让我们试一试,

  1. Convert the clientHash.getJSONObject("client_auth_hash") in String then byteArray,
  2. 将clienthass . getjsonobject(“client_auth_hash”)转换为字符串,然后是byteArray,
  3. then use,

    然后使用,

    byte temp[];
    Base64 b = new Base64();
    String jsonString = clientHash.getJSONObject("client_auth_hash").toString();
    temp = b.decode(jsonString.getBytes());
    
  4. then use your temp byte[].

    然后使用您的临时字节[]。

Hope this will help you. If its work then inform me. Thanx.

希望这能对你有所帮助。如果它的工作通知我。谢谢。