我可以发送请求并收到响应,但我无法解析响应.它返回以下错误:
Local Name:Body
error is here
java.lang.NullPointerException
at com.ticketmaster.ticketmaster.TicketMaster.Search(TicketMaster.java:119)
at com.ticketmaster.ticketmaster.App.main(App.java:12)
Run Code Online (Sandbox Code Playgroud)
码
SOAPMessage response
= connection.call(message, endpoint);
connection.close();
SOAPMessage sm = response;
SOAPBody sb = response.getSOAPBody();
System.err.println("Node Name:" + sb.getNodeName()); //return nothing
System.err.println("Local Name:" + sb.getLocalName()); //return Local Name:Body
DOMSource source = new DOMSource(sb);
results = (FindEventsResponse) JAXB.unmarshal(source, FindEventsResponse.class);
System.err.println("Results size: " + this.results.returnTag.results.item.get(0).getName());
} catch (Exception ex) {
System.err.println("error is here");
ex.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)
响应:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ns1="http://ticketmaster.productserve.com/v2/soap.php"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<ns1:findEventsResponse>
<return xsi:type="ns1:Response">
<details …Run Code Online (Sandbox Code Playgroud) 我有以下代码:
StringReader contentReader = new StringReader(this.dataContent.ToString());
Run Code Online (Sandbox Code Playgroud)
解析我的DataContent后,我需要重置contentReader的poistion以开始字符串.我该怎么做?我在StringReader中没有看到set poistion选项
它不是'&'
我使用SAXParser对象确实解析了实际的XML.
这通常通过将URL传递给XMLReader.Parse方法来完成.因为我的XML来自对Web服务的POST请求,所以我将该结果保存为String,然后使用StringReader/InputSource将此字符串反馈回XMLReader.Parse方法.
但是,在XMLstring的第2001个字符处发生了一些奇怪的事情.
文档处理程序的'characters'方法在startElement和endElement方法之间被称为TWICE,有效地将我的字符串(在本例中为项目标题)分成两部分.因为我在我的character方法中实例化对象,所以我得到两个对象而不是一个.
这条线,大约2000个字符串进入字符串"两个字符串",在"低级"和"级别"之间断开
<title>SUMC-BOOKSTORE, LOWER LEVEL RENOVATIONS</title>
Run Code Online (Sandbox Code Playgroud)
当我绕过StringReader/InputSource变通方法并将平面XML文件提供给XMLReader.Parse时,它可以正常工作.
关于StringReader和/或InputSource的东西在某种程度上搞砸了.
这是我的方法,XML字符串和解析是通过SAXParser.
public void parseXML(String XMLstring) {
try {
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp = spf.newSAXParser();
XMLReader xr = sp.getXMLReader();
xr.setContentHandler(this);
// Something is happening in the StringReader or InputSource
// That cuts the XML element in half at the 2001 character mark.
StringReader sr = new StringReader(XMLstring);
InputSource is = new InputSource(sr);
xr.parse(is);
} catch (IOException e) {
Log.e("CMS1", e.toString());
} catch (SAXException e) {
Log.e("CMS2", e.toString()); …Run Code Online (Sandbox Code Playgroud) 我使用a StringReader来读取多行文本框中的输入.但是,我遇到了奇怪的行为.
我的代码:
string x = reader.ReadLine();
int y = int.Parse(x);
Run Code Online (Sandbox Code Playgroud)
x总是一个int.
我的问题是,因为x是多行文本框的第一行,它不仅包含int,但是System.Windows.Forms.Textbox, Text:10
这里有任何帮助吗?
我创建StringReader如下:
using (StringReader reader = new StringReader(Convert.ToString(multilinetbox)))
{
}
Run Code Online (Sandbox Code Playgroud) 我想读取此字符串(来自控制台而不是文件),例如:
one two three
four five six
seven eight nine
Run Code Online (Sandbox Code Playgroud)
所以我想每行读取它并将每一行放在一个数组中.我怎么读呢?因为如果我使用扫描仪,我只能读一行或一个单词(下一行或下一行).
我的意思是阅读例如: one two trhee \n four five six \n seven eight nine...
我有一个包含多行的字符串,如下所示
<?xml version="1.0" encoding="UTF-8"?>
<books>
<book publishyear="1990">
<name>Harry Potter</name>
</book>
</books>
Run Code Online (Sandbox Code Playgroud)
如何将其写入文件?我尝试过使用缓冲编写器,但它不会在多行中使用字符串.
try{
FileWriter fstream = new FileWriter("D:/temp.txt");
BufferedWriter out = new BufferedWriter(fstream);
out.write(" <?xml version="1.0" encoding="UTF-8"?>
<books>
<book publishyear="1990">
<name>Harry Potter</name>
</book>
</books>");
out.close();
}catch (Exception e){//Catch exception if any
System.err.println("Error: " + e.getMessage());
}
Run Code Online (Sandbox Code Playgroud) 我有一个大字符串要读,它总是不同的,但一个字总是一样的.这个词是MESSAGE,所以如果我的字符串阅读器遇到这个词,它必须将整个字符串写入光盘.我做了一些代码,但它没有工作,if段永远不会触发,这里有什么问题?
string aLine;
StringReader strRead = new StringReader(str);
aLine = strRead.ReadLine();
if (aLine == "MESSAGE")
{
//Write the whole file on disc
}
Run Code Online (Sandbox Code Playgroud) 我正在对 .NET 和 C# 中的 StringReader 类进行一些研究,使用此处找到的实现: https: //referencesource.microsoft.com/#mscorlib/system/io/stringreader.cs
我创建了一个小类,我认为它使用相同的基本实现来读取字符串,但令我惊讶的是我的代码比 .NET StringReader 慢两倍多。
这是我的课程:
public class DataReader
{
private String source;
private int pos;
private int length;
public DataReader(string data)
{
source = data;
length = source.Length;
}
public int Peek()
{
if (pos == length) return -1;
return source[pos];
}
public int Read()
{
if (pos == length) return -1;
return source[pos++];
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的测试代码:
using System;
using System.IO;
using System.Diagnostics;
using System.Text;
using System.Collections.Generic;
public class Program
{ …Run Code Online (Sandbox Code Playgroud) stringreader ×8
c# ×4
java ×4
multiline ×2
string ×2
android ×1
filewriter ×1
jaxb ×1
performance ×1
sax ×1
soap ×1
textbox ×1
winforms ×1
xml ×1