-1

我有一个这样的 JSON 字符串:

["<a href='http://adda.com/jsonFeed/faJsonFeedDetails.php?jid=12036'>SPICE JET Recruits Freshers Data Entry Operator in Gurgaon</a><br><br><br>","<a href='http://adda.com/jsonFeed/faJsonFeedDetails.php?jid=12035'>TOSHIBA Freshers off Campus Drive Trainee Engineers in Bangalore </a><br><br><br>","<a href='http://adda.com/jsonFeed/faJsonFeedDetails.php?jid=12034'>EMC Corporation Recruits Fresher Jobs Technical Support Engineers in bangalore</a><br><br><br>"]

我想从上面的 JSON 字符串中解析href值。title任何人都可以帮忙吗?

4

3 回答 3

4

试试下面的代码。

try {
    JSONArray ja = new JSONArray(json);
    int size = ja.length();
    Log.d("tag","No of Elements " + ja.length());
    for (int i = 0; i < size; i++) {
        String str = ja.getString(i);
        String href = str.substring(str.indexOf("href=") + 5,
                str.indexOf(">"));
        Log.d("tag",href);
    }
} catch (JSONException e) {
    e.printStackTrace();
}

在这段代码中,json将是你的字符串,比如

String json = "[\"<a href='http://adda.com/jsonFeed/faJsonFeedDetails.php?jid=12036'>SPICE JET Recruits Freshers Data Entry Operator in Gurgaon</a><br><br><br>\",\"<a href='http://adda.com/jsonFeed/faJsonFeedDetails.php?jid=12035'>TOSHIBA Freshers off Campus Drive Trainee Engineers in Bangalore </a><br><br><br>\",\"<a href='http://adda.com/jsonFeed/faJsonFeedDetails.php?jid=12034'>EMC Corporation Recruits Fresher Jobs Technical Support Engineers in bangalore</a><br><br><br>\"]";

输出将如下所示。

06-04 16:50:44.632: tag : 'http://adda.com/jsonFeed/faJsonFeedDetails.php?jid=12036'
06-04 16:50:44.632: tag : 'http://adda.com/jsonFeed/faJsonFeedDetails.php?jid=12035'
06-04 16:50:44.632: tag : 'http://adda.com/jsonFeed/faJsonFeedDetails.php?jid=12034'
于 2013-06-04T11:22:19.437 回答
1

在 Android 官方文档中查看此主题,并查看以下 SO 答案:

在这里,您有一个使用Spring for Android检索 JSON 数组的工作示例(通过使用 REST 服务)。

于 2013-06-04T15:10:15.573 回答
0

很简单。从 JSONArray 中获取 JSONObjects,然后分别解析每个 JSONObject。更多细节可以查看Android JSON Parsing Tutorial

于 2013-06-04T11:07:46.180 回答