在logcat上以json的形式获得响应

时间:2011-03-31 14:16:10

标签: android json logcat

{
    "Generalinfor": {
        "type": "Response",
        "name": "abcde",
        "ver": "3.0.0" 
    },
    "Login": {
        "errorCode": "001",
        "errorMsg": "Login Failed - Missing of Password",
        "userID": "0",
        "versionAvail": "",
        "versionDownloadMsg": "can't login " 
    } 
} 

我正在从我的网络服务器json获得logcat格式的响应。现在我想将其转换为字符串并在模拟器上显示此图像。我怎么能做到这一点?

请向我提供任何可能的提示或示例代码。

1 个答案:

答案 0 :(得分:2)

import org.json.JSONObject;

JSONObject jObject = new JSONObject(yourJsonString);

http://www.json.org/javadoc/org/json/JSONObject.html

String type = (String) jObject.get("type"); // would return your type 'Response'

http://www.json.org/javadoc/org/json/JSONObject.html#get(java.lang.String

等...