如何将JSON对象转换为类对象对象、转换为、如何将、JSON

由网友(暖心)分享简介:如何转换这个JSON clsError和用户id值How to convert this json clsError and userId values字符串TEMP ={clsError:{错误code:110,ErrorDescription中:要求增加},用户名:36} 和它们作为参数传递clsError e...

如何转换这个JSON clsError和用户id值

How to convert this json clsError and userId values

字符串TEMP ={clsError:{错误code:110,ErrorDescription中:要求增加},用户名:36}

和它们作为参数传递

clsError errorObject =新clsError(用户ID,clsError);

推荐答案

第一次使用这样的:http://developer.android.com/reference/org/json/JSONObject.html#JSONObject(java.lang.String)

JSONObject tempJson = new JSONObject(temp);
JSONObject clsErrorJson = tempJson.getJSONObject("clsError");
clsError errorObject = new clsError(tempJson.getString("UserID"),
                                    clsErrorJson.getInt("clsError") + ": "
                                    + clsErrorJson.getString("ErrorDescription"));

这基本上是它。但我不知道的clsError构造函数的第二个参数。我只是认为这是在我的例子字符串:),但是这应该给你的想法如何做到这一点。你将有环绕与try / catch语句。月食将告诉你如何:)

that is basically it. but i was not sure about the second parameter of the clsError constructor. i just assumed it is a string in my example :) but this should give you the idea how to do this. and you will have to surround that with try/catch. eclipse will tell you how :)

阅读全文

相关推荐

最新文章