gpt4 book ai didi

java - 通过缓冲阅读器读取 php...我如何区分行的变化?

转载 作者:太空宇宙 更新时间:2023-11-04 12:54:12 25 4
gpt4 key购买 nike

我正在尝试在 Android 应用程序中使用 BufferedReader 读取 php 文件。但我的读者将


读作文本而不是换行...我的代码是这样的

            HttpEntity entityResponse = res.getEntity();
InputStream im = entityResponse.getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(im, HTTP.UTF_8));

String tmp = "";
while((tmp = reader.readLine())!= null)
{
if(tmp != null)
{
total1.add(tmp);
Log.d("testq", "total1."+i+" "+tmp);
tmp = reader.readLine();
total2.add(tmp);
Log.d("testq", "total2."+i+" "+tmp);
tmp = reader.readLine();
total3.add(tmp);
Log.d("testq", "total3."+i+" "+tmp);
tmp = reader.readLine();
total4.add(tmp);
Log.d("testq", "total4."+i+" "+tmp);
tmp = reader.readLine();
total5.add(tmp);
Log.d("testq", "total5."+i+" "+tmp);
tmp = reader.readLine();
total6.add(tmp);
Log.d("testq", "total6."+i+" "+tmp);
}
}

我有 6 个字符串 ArrayList 的原因是因为在我的例子中这六行是一组数据。但是当我检查里面的数据时,

02-22 15:55:39.557: D/testq(2030): total1.0 2</p>0</p>upload/Ww2016. 2. 22. 3:55:16.png</p>Qq</p>ee</p></p>
02-22 15:55:39.557: D/testq(2030): total2.0 null
02-22 15:55:39.557: D/testq(2030): total3.0 null
02-22 15:55:39.557: D/testq(2030): total4.0 null
02-22 15:55:39.557: D/testq(2030): total5.0 null
02-22 15:55:39.557: D/testq(2030): total6.0 null

虽然应该如此

total1.0 - 2
total2.0 - 0
total3.0 - upload/Ww2016. 2. 22. 3:55:16.png
total4.0 - qq
total5.0 - ee
total6.0 - null

我怎样才能正确读出这些

最佳答案

好吧</p>不是换行符,因此没有理由将其读取为换行符。 BufferedReader 对 html 一无所知。如果您需要担心的只是</p></br> ,那么你可以使用string.split()将数据分成几部分。但实际上,除非您正在屏幕抓取您无法控制的网站,否则发送 JSON 或 XML 对象比解析 html 要好得多。

关于java - 通过缓冲阅读器读取 php...我如何区分行的变化?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35547543/

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