Home > Mobile >  The great spirit consult
The great spirit consult

Time:10-20

1. The following json string parsing, and print to TextView
{
"Code" : "1",
"MSG", "success",
"Version" : ", "
"Time" : "1557228580",
"Data" : [
{
"Type" : "empty",
"Data" : {
"Height" : "","
}
},
{
"Type" : "banner,"
"Data" : {
"Height" : ", "
"Banner", "
"}
}
]
}
2. Through the TextView handler change the page content,

CodePudding user response:

Json parsing is a jar package, own research,
After the json parsing is complete, invoke Message. Obtain (); To create the Message object, the MSG. Obj assignment, value the parsed data for you, then call your handler invocation sendMessage (MSG); The data to send,

Create a handler object in which the rewrite handlerMessage (Message MSG) method
MSG. Obj is passed the data, you need casts,
Then calls the textView. SetText (STR) to update the UI
BltStatusHandler=new Handler () {
@ Override
Public void handleMessage (Message MSG) {
Super. HandleMessage (MSG);
String STR=(String) MSG. Obj;
TextView. SetText (STR);
}
};

CodePudding user response:

 
The json String String jsonStr="you"
JSONObject jsonObj=JSONObject (jsonStr);

//remove data
Try {
String code=(String) jsonObj. Get (" code ")
//or String code=jsonObj. Get String (" code ")
} the catch (Exception e) {
E.p rintStackTrace ()
}
  • Related