我收到以下错误“.XmlPullParserException: Unexpected token (position:TEXT ["@1:3"
执行以下操作时
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpGet get = new HttpGet(url);
HttpResponse response = httpClient.execute(get);
int status = response.getStatusLine().getStatusCode();
HttpEntity entity = response.getEntity();
String jSONData = EntityUtils.toString(entity);
if (json.has("games"))
{
strJson = json.getString("games");
}
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
factory.setNamespaceAware(true);
XmlPullParser xpp = factory.newPullParser();
xpp.setInput(new StringReader(strJson));
int eventType = xpp.getEventType();
while (eventType != XmlPullParser.END_DOCUMENT)
{
if (eventType == XmlPullParser.START_DOCUMENT)
{
System.out.println("Start document");
}
else if (eventType == XmlPullParser.END_DOCUMENT)
{
System.out.println("End document");
}
else if (eventType == XmlPullParser.START_TAG)
{
System.out.println("Start tag " + xpp.getName());
}
else if (eventType == XmlPullParser.END_TAG)
{
System.out.println("End tag " + xpp.getName());
}
else if (eventType == XmlPullParser.TEXT)
{
System.out.println("Text " + xpp.getText());
}
eventType = xpp.next();//Here is Where I am getting error!!
}
}
catch (Exception e)
{
e.printStackTrace();
}
编辑:这是 JSON。我想解析“游戏”
{
"sport": "NBA",
"period": "20140420",
"games": [
"<ticker-entry gamecode=\"2014042024\" gametype=\"Playoffs\"><visiting-team display_name=\"Dallas\" alias=\"Dal\" nickname=\"Mavericks\" id=\"6\" division=\"WCS\" conference=\"WC\" score=\"85\"><score heading=\"1\" value=\"12\" team-fouls=\"2\"></score><score heading=\"2\" value=\"32\" team-fouls=\"3\"></score><score heading=\"3\" value=\"21\" team-fouls=\"7\"></score><score heading=\"4\" value=\"20\" team-fouls=\"6\"></score><score heading=\"T\" value=\"85\"></score></visiting-team><home-team display_name=\"San Antonio\" alias=\"SA\" nickname=\"Spurs\" id=\"24\" division=\"WCS\" conference=\"WC\" score=\"90\"><score heading=\"1\" value=\"21\" team-fouls=\"3\"></score><score heading=\"2\" value=\"22\" team-fouls=\"4\"></score><score heading=\"3\" value=\"22\" team-fouls=\"4\"></score><score heading=\"4\" value=\"25\" team-fouls=\"5\"></score><score heading=\"T\" value=\"90\"></score></home-team><gamestate status=\"Final\" display_status1=\"Final\" display_status2=\"\" href=\"http://scores.nbcsports.msnbc.com/nba/recap.asp?g=2014042024\" tv=\"TNT/FSSW\" gametime=\"1:00 PM\" gamedate=\"4/20\" is-dst=\"1\" is-world-dst=\"1\"></gamestate></ticker-entry>"
,"<ticker-entry gamecode=\"2014042014\" gametype=\"Playoffs\"><visiting-team display_name=\"Charlotte\" alias=\"Cha\" nickname=\"Bobcats\" id=\"30\" division=\"ECS\" conference=\"EC\" score=\"88\"><score heading=\"1\" value=\"23\" team-fouls=\"4\"></score><score heading=\"2\" value=\"19\" team-fouls=\"6\"></score><score heading=\"3\" value=\"23\" team-fouls=\"4\"></score><score heading=\"4\" value=\"23\" team-fouls=\"3\"></score><score heading=\"T\" value=\"88\"></score></visiting-team><home-team display_name=\"Miami\" alias=\"Mia\" nickname=\"Heat\" id=\"14\" division=\"ECS\" conference=\"EC\" score=\"99\"><score heading=\"1\" value=\"19\" team-fouls=\"2\"></score><score heading=\"2\" value=\"30\" team-fouls=\"3\"></score><score heading=\"3\" value=\"23\" team-fouls=\"1\"></score><score heading=\"4\" value=\"27\" team-fouls=\"6\"></score><score heading=\"T\" value=\"99\"></score></home-team><gamestate status=\"Final\" display_status1=\"Final\" display_status2=\"\" href=\"http://scores.nbcsports.msnbc.com/nba/recap.asp?g=2014042014\" tv=\"ABC\" gametime=\"3:30 PM\" gamedate=\"4/20\" is-dst=\"1\" is-world-dst=\"1\"></gamestate></ticker-entry>"
,"<ticker-entry gamecode=\"2014042004\" gametype=\"Playoffs\"><visiting-team display_name=\"Washington\" alias=\"Was\" nickname=\"Wizards\" id=\"27\" division=\"ECS\" conference=\"EC\" score=\"102\"><score heading=\"1\" value=\"24\" team-fouls=\"4\"></score><score heading=\"2\" value=\"24\" team-fouls=\"9\"></score><score heading=\"3\" value=\"24\" team-fouls=\"5\"></score><score heading=\"4\" value=\"30\" team-fouls=\"6\"></score><score heading=\"T\" value=\"102\"></score></visiting-team><home-team display_name=\"Chicago\" alias=\"Chi\" nickname=\"Bulls\" id=\"4\" division=\"ECC\" conference=\"EC\" score=\"93\"><score heading=\"1\" value=\"22\" team-fouls=\"7\"></score><score heading=\"2\" value=\"32\" team-fouls=\"8\"></score><score heading=\"3\" value=\"21\" team-fouls=\"2\"></score><score heading=\"4\" value=\"18\" team-fouls=\"8\"></score><score heading=\"T\" value=\"93\"></score></home-team><gamestate status=\"Final\" display_status1=\"Final\" display_status2=\"\" href=\"http://scores.nbcsports.msnbc.com/nba/recap.asp?g=2014042004\" tv=\"TNT/CSNC/CSNB\" gametime=\"7:00 PM\" gamedate=\"4/20\" is-dst=\"1\" is-world-dst=\"1\"></gamestate></ticker-entry>"
,"<ticker-entry gamecode=\"2014042010\" gametype=\"Playoffs\"><visiting-team display_name=\"Portland\" alias=\"Por\" nickname=\"Trail Blazers\" id=\"22\" division=\"WCN\" conference=\"WC\" score=\"122\"><score heading=\"1\" value=\"27\" team-fouls=\"3\"></score><score heading=\"2\" value=\"21\" team-fouls=\"3\"></score><score heading=\"3\" value=\"25\" team-fouls=\"7\"></score><score heading=\"4\" value=\"33\" team-fouls=\"10\"></score><score heading=\"OT\" value=\"16\" team-fouls=\"5\"></score><score heading=\"T\" value=\"122\"></score></visiting-team><home-team display_name=\"Houston\" alias=\"Hou\" nickname=\"Rockets\" id=\"10\" division=\"WCS\" conference=\"WC\" score=\"120\"><score heading=\"1\" value=\"20\" team-fouls=\"5\"></score><score heading=\"2\" value=\"29\" team-fouls=\"7\"></score><score heading=\"3\" value=\"30\" team-fouls=\"5\"></score><score heading=\"4\" value=\"27\" team-fouls=\"8\"></score><score heading=\"OT\" value=\"14\" team-fouls=\"4\"></score><score heading=\"T\" value=\"120\"></score></home-team><gamestate status=\"Final\" display_status1=\"Final\" display_status2=\"OT\" href=\"http://scores.nbcsports.msnbc.com/nba/recap.asp?g=2014042010\" tv=\"TNT/CSNH/KGW\" gametime=\"9:30 PM\" gamedate=\"4/20\" is-dst=\"1\" is-world-dst=\"1\"></gamestate></ticker-entry>"
]}