gpt4 book ai didi

android - 无法正确获取 xml 中的数据解析

转载 作者:行者123 更新时间:2023-11-30 03:38:00 25 4
gpt4 key购买 nike

这里我没有数据,然后我得到了 Pcode 0,但是在这里我无法得到 Pcode 0,我的目的是让 Pcode 为零并显示 “这里没有数据” 消息。我已经使用 xml 进行数据解析,但无法正确解析,我有解析错误的错误,但无法找到,我在哪里做错了。这是我的代码:

 Log.d("user id is ", userId + "!");                

String input = String.format("<Es_Request><Data><UserId>%s</UserId></Data></Es_Request>", userId);
String response = HttpPostRetreiver .retriver(Url.url_getting_assignment, input, GradeAssignmentActivity.this);
if (response != null) {
esResponse = XmlParser.parseAssignmentProfessorResponse(response);
Log.d("TAG", "Checking Value="+ esResponse.getResponseCode().getpCode());
if (esResponse.getResponseCode().getpCode().equalsIgnoreCase("1")) {
assignmentDataInfo = esResponse .getAssignmentListData().getAssignmentDataInfo();
int size = assignmentDataInfo.size();
int i = 0;
for (; i < size; i++) {
EduInterface.assignmetIdArrayList.add(assignmentDataInfo.get(i).getAssignmentId());
EduInterface.assignmetNameArrayList.add(assignmentDataInfo.get(i).getAssignmentName());
}
} else {

test = 1;
Log.d("else", "Not data Here");
}
}

} else {
Log.d("TAG", "Error in Webservice");

}
} catch (Exception e) {
Log.e("Grade Assignment class", e.toString() + "");
}

我知道了,第一个用户id是5!然后得到错误 Grade Assignemt Class 错误。我解析一直有问题 这里是pasing>

输入字符串: Es_Request><Data><UserId>913</UserId></Data></Es_Request>

响应字符串:

<?xml version="1.0" encoding="utf-8"?><Es_Response><Es_Session_Id></Es_Session_Id>
<Bpn_Request_Id></Bpn_Request_Id><Response_Code><Pcode>0</Pcode><Scode>Unsuccessful</Scode></Response_Code><Data><message>Assignments not found for Professor & CourseId.</message></Data></Es_Response>

这是我的处理程序类:

@Override
public void startElement(String uri, String localName, String qName,
Attributes atts) throws SAXException {
content = new StringBuilder();
if (localName.equalsIgnoreCase("Data")) {
assignmentListData=new AssignmentListData();
} else if (localName.equalsIgnoreCase("assignments")) {
assignmentItems = new AssignmentItems();
}
else if (localName.equalsIgnoreCase("Es_Response")) {
esResponse=new EsResponse();
} else if (localName.equalsIgnoreCase("Response_Code")) {
responseCode=new ResponseCode();
}
}
@Override
public void endElement(String uri, String localName, String qName)
throws SAXException {
if (localName.equalsIgnoreCase("Pcode")) {
responseCode.setpCode(content.toString());
Log.d("TAG", "Pcode Value->"+content.toString());
}
else if (localName.equalsIgnoreCase("Response_Code")) {
esResponse.setResponseCode(responseCode);
}
else if (localName.equalsIgnoreCase("AssignmentId")) {
assignmentItems.setAssignmentId(content.toString());
}
else if (localName.equalsIgnoreCase("AssignmentName")) {
assignmentItems.setAssignmentName(content.toString());
}

else if (localName.equalsIgnoreCase("Assignments")) {
assignmentDataInfo.add(assignmentItems);
}
else if (localName.equalsIgnoreCase("Data")) {
assignmentListData.setAssignmentDataInfo(assignmentDataInfo);
}
else if (localName.equalsIgnoreCase("Es_Response")) {
esResponse.setAssignmentListData(assignmentListData);
}

}

我得到了这个 logcat:

04-30 19:25:51.378: D/getting course list->(1598): Line 322---RESPONSE<?xml version="1.0" encoding="utf-8"?><Es_Response><Es_Session_Id></Es_Session_Id>
04-30 19:25:51.378: D/getting course list->(1598): <Bpn_Request_Id></Bpn_Request_Id><userIDName>913</userIDName><schoolID>1</schoolID><CourseID>977</CourseID><Response_Code><Pcode>0</Pcode><Scode>Unsuccessful</Scode><Test>977</Test><ROLE ID>4</ROLE ID></Response_Code><Data><message>Assignments not found for Professor & CourseId.</message></Data></Es_Response>
04-30 19:25:51.378: D/user id is(1598): 913
04-30 19:25:51.378: D/school id is(1598): 1
04-30 19:25:51.388: D/TAG(1598): Pcode Value->0
04-30 19:25:51.398: W/System.err(1598): org.apache.harmony.xml.ExpatParser$ParseException: At line 2, column 189: not well-formed (invalid token)
04-30 19:25:51.398: W/System.err(1598): at org.apache.harmony.xml.ExpatParser.parseFragment(ExpatParser.java:499)
04-30 19:25:51.398: W/System.err(1598): at org.apache.harmony.xml.ExpatParser.parseDocument(ExpatParser.java:484)
04-30 19:25:51.409: W/System.err(1598): at org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:309)
04-30 19:25:51.409: W/System.err(1598): at org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:267)
04-30 19:25:51.409: W/System.err(1598): at sdei.edustatusnew.services.XmlParser.parseAssignmentProfessorResponse(XmlParser.java:840)
04-30 19:25:51.409: W/System.err(1598): at sdei.edustatusnew.gradebook.GradeAssignmentActivity$GetDataTask.doInBackground(GradeAssignmentActivity.java:326)
04-30 19:25:51.409: W/System.err(1598): at sdei.edustatusnew.gradebook.GradeAssignmentActivity$GetDataTask.doInBackground(GradeAssignmentActivity.java:1)
04-30 19:25:51.427: W/Trace(1598): Unexpected value from nativeGetEnabledTags: 0
04-30 19:25:51.427: W/Trace(1598): Unexpected value from nativeGetEnabledTags: 0
04-30 19:25:51.438: W/Trace(1598): Unexpected value from nativeGetEnabledTags: 0
04-30 19:25:51.438: W/Trace(1598): Unexpected value from nativeGetEnabledTags: 0
04-30 19:25:51.468: W/System.err(1598): at android.os.AsyncTask$2.call(AsyncTask.java:287)
04-30 19:25:51.478: W/System.err(1598): at java.util.concurrent.FutureTask.run(FutureTask.java:234)
04-30 19:25:51.478: W/System.err(1598): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
04-30 19:25:51.488: W/System.err(1598): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
04-30 19:25:51.488: W/System.err(1598): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
04-30 19:25:51.488: W/System.err(1598): at java.lang.Thread.run(Thread.java:856)
04-30 19:25:51.488: E/Grade Assignment class(1598): java.lang.NullPointerException

请你帮忙,我的代码有什么错误。提前致谢。

最佳答案

您的 XML 中有错误。在您的 logcat 堆栈跟踪中非常清楚,即 org.apache.harmony.xml.ExpatParser$ParseException: At line 2, column 189: not well-formed (invalid token)

第 2 行第 189 列的标签是 <ROLE ID>4</ROLE ID> . XML 标记不应包含任何空白字符。

解决办法是改成<ROLE_ID>4</ROLE_ID>

关于android - 无法正确获取 xml 中的数据解析,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16307894/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com