如何从android中的json解析数据?

时间:2012-11-29 06:58:21

标签: android json

我已经从android调用了webservice并得到了如下的响应.....

WebService =

的结果
11-30 13:21:16.304: DEBUG/Inside SOAP(512): JSON output {
11-30 13:21:16.304: DEBUG/Inside SOAP(512):   "_str": "anyType{string\u003dImplements and Equipments; string\u003dInsurance; string\u003dIrrigation and Water; }"
11-30 13:21:16.304: DEBUG/Inside SOAP(512): }

现在我想解析这些结果并存储在我的SQLite数据库中。怎么做?我需要你的帮助......

1 个答案:

答案 0 :(得分:3)

我假设您希望获得“=”之后的每个字符串,并且在“;”之前

这是一个简单的例子:

// This is the string you want to parse
String searchableString = "string=first; string=second; string=third";

int indexOfEqualsSign = searchableString.indexOf("=");
int indexOfSemicolon = searchableString.indexOf(";");

while (indexOfEqualsSign >= 0) {
    String result = searchableString.substring(indexOfEqualsSign + 1, indexOfSemicolon);
    System.out.print(result);
    indexOfEqualsSign = searchableString.indexOf("=", indexOfSemicolon);
}

示例的输出如下所示:

first
second
third