I have this String
response from server:
[{"name":"Abe","msg":"Hello, this is my message","age":33,"height":1.75},{"name":"Ben","msg":"I love play guitar :) ","age":18,"height":1.8} ...
And I have to arrange this response in an ArrayList<MyUser>
At the moment I'm using the following code:
String s[] = myresponse.split("\n|\\W");
String temp = "";
for(String z : s) {
temp += z + "\n";
}
s = temp.split("\n+");
temp = "";
for(String z : s) {
temp += z + " ";
}
Log.d("MyActivity", temp);
But it is a bit tricky and I lose all the non-word character in the msg "column", which I should save as a String
, and the .
in the height "column", which i need to save as a float
value in the MyUser
class.
So, is there a easiest way to split this string using .split
method an RegEx or I should write my own method to do this? Thanks.
MyUser
public class MyUser {
private String name, msg;
private int age;
private float height;
public Friends(String name, String msg, int age, float height) {
this.name = username;
this.msg = msg;
this.age = age;
this.height = height;
}
}