gpt4 book ai didi

java - 获取 org.json.JSONException : End of input at character 0 errror in Android App

转载 作者:行者123 更新时间:2023-12-01 12:37:39 28 4
gpt4 key购买 nike

在我的问题之前,我已经尝试了“org.json.JSONException:字符 0 处的输入结束”给出的所有答案,

但我的应用程序没有找到正确的方法,请帮助我,

日志

08-22 10:59:45.112: I/System.out(6677): .....reader.readLine()..........  [{"m_id":1,"send_id":1,"user_name_from":"mahi ","user_imei_from":"356605052523574","message":"mahi","time_date":"2014-08-21 05:32:15 PM","item":null,"qty":null,"image":null,"user_name_to":"demo","user_imei_to":"000000000000000"}]
08-22 10:59:45.122: W/System.err(6677): org.json.JSONException: End of input at character 0 of
08-22 10:59:45.122: W/System.err(6677): at org.json.JSONTokener.syntaxError(JSONTokener.java:450)
08-22 10:59:45.132: W/System.err(6677): at org.json.JSONTokener.nextValue(JSONTokener.java:97)
08-22 10:59:45.132: W/System.err(6677): at org.json.JSONArray.<init>(JSONArray.java:87)
08-22 10:59:45.132: W/System.err(6677): at org.json.JSONArray.<init>(JSONArray.java:103)
08-22 10:59:45.132: W/System.err(6677): at com.pis.pisservices.AllMessageService$sync.doInBackground(AllMessageService.java:167)
08-22 10:59:45.152: W/System.err(6677): at com.pis.pisservices.AllMessageService$sync.doInBackground(AllMessageService.java:1)
08-22 10:59:45.152: W/System.err(6677): at android.os.AsyncTask$2.call(AsyncTask.java:264)
08-22 10:59:45.152: W/System.err(6677): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
08-22 10:59:45.152: W/System.err(6677): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
08-22 10:59:45.152: W/System.err(6677): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:208)
08-22 10:59:45.162: W/System.err(6677): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
08-22 10:59:45.162: W/System.err(6677): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
08-22 10:59:45.162: W/System.err(6677): at java.lang.Thread.run(Thread.java:856)

Activity 中

protected Void doInBackground(Void... params) 
{
HttpClient client= new DefaultHttpClient();
HttpGet getrequest= new HttpGet(SERVICE_URL);

try
{
System.out.println("..........sync...All msg..Service...In try........");
HttpResponse response=client.execute(getrequest);
System.out.println("....jsdata.response..."+response);
InputStream jsdata= response.getEntity().getContent();
System.out.println("....jsdata.InputStream..."+jsdata);
BufferedReader reader= new BufferedReader(new InputStreamReader(jsdata));
StringBuilder builder = new StringBuilder();
String line;
System.out.println(".....reader.readLine().........."+reader.readLine());

while((line=reader.readLine())!=null)
{
builder.append(line);
System.out.println("....builder.append(line);..."+builder.append(line));
}
String Jsondata=builder.toString();

JSONArray item=new JSONArray(Jsondata);
// System.out.println(".....JSONArray..item...."+item);

int temp=item.length();

System.out.println("...All msg.temp...."+temp);

if(item != null)
{
Cursor cur = dbh.getblankIdCUR();

System.out.println("...dbh.getblankIdCUR()....."+dbh.getblankIdCUR());
for(int i = 0; i < item.length(); i++){
if(i<temp)
{
JSONObject c = item.getJSONObject(i);
String m_id =c.getString(TAGm_id);
String send_id =c.getString(TAG_send_id);
String from_name =c.getString(TAGfrom_name);
String from_imei = c.getString(TAGfrom_imei);
String msg = c.getString(TAGMessage);
String msg_img = c.getString(TAGmsg_image);
String m_item=c.getString(TAGitem);
String Qty = c.getString(TAGQty);
String time_date = c.getString(TAGtime_date);
String to_imei = c.getString(TAGto_imei);
String to_name = c.getString(TAGto_name);

String Unique_id = from_imei + time_date;


System.out.println("......All msg..Service....sdds...........");
System.out.println("...msg..cur.getCount() ..........."+cur.getCount() );

// update the sent message
if(cur.getCount() != 0)
{ System.out.println("........Service...ssssssssssss............");
cur.moveToFirst();
do {

int snd=cur.getInt(1);
String s= Integer.toString(snd);
System.out.println("........send_id.equalsIgnoreCase(s)...fdf........"+send_id.equalsIgnoreCase(s));

if(send_id.equalsIgnoreCase(s))
{
System.out.println("........send_id.equalsIgnoreCase(s)..........."+send_id.equalsIgnoreCase(s));
dbh.updatemessage(from_imei,send_id,m_id,time_date);
break;
}
} while (cur.moveToNext());
}

// get messages which has been send by other
else if((send_id.equalsIgnoreCase("0")) && ((!from_imei.equalsIgnoreCase(Imei_no)) || (from_imei.equalsIgnoreCase(Imei_no))))
{
dbh.Insert_msgdata(m_id,send_id, from_name, from_imei, msg, msg_img, m_item, Qty, time_date, to_imei, to_name);

showNotification(from_name);
}
// get all messages which after data clear
else
{

dbh.Insert_msgdata(m_id,send_id, from_name, from_imei, msg, msg_img, m_item, Qty, time_date, to_imei, to_name);
}
}
}

}






}
catch (JSONException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}

杰森字符串

[{"m_id":1,"send_id":1,"user_name_from":"mahi","user_imei_from":"356605052523574","message":"mahi","time_date":"2014-08- 21 05:32:15 PM","item":null,"qty":null,"image":null,"user_name_to":"demo","user_imei_to":"000000000000000"}]

  1. 我的 jason 没有获取 null ,这意味着它有一些值。

  2. 我已在本地尝试过此操作,但尚未完成。

  3. 我使用了Get方法。

所以,请帮我解决这个问题。谢谢。

最佳答案

改变

String line;
System.out.println(".....reader.readLine().........."+reader.readLine());

while((line=reader.readLine())!=null)
{
builder.append(line);
System.out.println("....builder.append(line);..."+builder.append(line));
}

while((line=reader.readLine())!=null)
{
System.out.println(".....reader.readLine().........."+ line);
builder.append(line);
System.out.println("....builder.append(line);..."+builder.append(line));
}

否则你正在读取该行,打印它并扔掉它,并且不会添加到 jsonData 变量

关于java - 获取 org.json.JSONException : End of input at character 0 errror in Android App,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25440547/

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