如何在Android中使用Java从服务器获取的字符串中使用Pipeline Break?

时间:2013-12-26 05:07:14

标签: java android split pipeline

我从服务器获取此字符串响应:

12-26 09:47:39.175: I/responseString(704): 46||2||1||"1234"||"Site ID"||""||"2012-09-17 05:22:04"||"2013-04-26 07:47:23"||0||1||1<br />47||2||1||"1234"||"Search Name"||""||"2012-09-17 05:27:07"||"2013-04-26 07:47:23"||0||1||2<br />48||2||1||"1234"||"Company Name"||""||"2012-09-17 05:27:45"||"2013-04-26 07:47:23"||0||1||3<br />49||2||1||"1234"||"Contact Person's Title"||""||"2012-09-17 05:28:42"||"2013-04-26 07:47:23"||0||1||4<br />50||2||1||"1234"||"Contact Person's Name"||""||"2012-09-17 05:29:19"||"2013-10-01 11:12:36"||1||1||5<br />

我使用过此代码,但无法正常使用。

 private void getSiteMenuFieldsData(String parameter)
            {
            String getSiteMenuFieldsData_String  = ServerRequest1.sendRequest(url,parameter);
            getSiteMenuFieldsData_Str_Array = getSiteMenuFieldsData_String.split("<br />");
            Log.i("getSiteMenuFieldsData_Str_Array:",""+ getSiteMenuFieldsData_Str_Array);

            for(int i=0;i<getSiteMenuFieldsData_Str_Array.length;i++)
            {
            Log.i("getParametersData_Str_Array :",getSiteMenuFieldsData_Str_Array[i]);
            Log.i("getSiteMenuFieldsData_Str_Array[i]:",""+getSiteMenuFieldsData_Str_Array[i].split("\\||"));
            String query =  "INSERT  INTO menu_fields(ID,menu_id,field_type_id,c4w_code,field_label,field_values,date_created,date_modified,is_required,is_static,field_order) " +
                "VALUES ("+getSiteMenuFieldsData_Str_Array[i].split("\\||")+");";
            Log.i("query result menu_fields:",""+query);
            db.execSQL(query);
   }
 }

这是LogCat:

  

12-26 09:47:40.331:I / getParametersData_Str_Array:(704):   46 || 2 || 1 ||“1234”||“网站ID”||“”||“2012-09-17 05:22:04”||“2013-04-26   07:47:23“|| 0 || 1 || 1 12-26 09:47:40.604:I / Choreographer(704):Skipped   90帧!应用程序可能在其主要方面做了太多工作   线。 12-26 09:47:41.125:   I / getSiteMenuFieldsData_Str_Array [I] :( 704):   [Ljava.lang.String; @ 41219a48 12-26 09:47:41.354:我/查询结果   menu_fields:(704):INSERT INTO   menu_fields(ID,menu_id,field_type_id,c4w_code,FIELD_LABEL,field_values,DATE_CREATED,DATE_MODIFIED,is_required,is_static,field_order)   VALUES([Ljava.lang.String; @ 413777e0];

,这是在表格中插入记录时的错误:

    > 
    >  12-26 09:47:41.384: W/System.err(704):
    > android.database.sqlite.SQLiteException: unrecognized token:
    > "[Ljava.lang.String;@413777e0);" (code 1): , while compiling: INSERT 
    > INTO

> menu_fields(ID,menu_id,field_type_id,c4w_code,field_label,field_values,date_created,date_modified,is_required,is_static,field_order)
> VALUES ([Ljava.lang.String;@413777e0); 12-26 09:47:41.394:
> W/System.err(704):    at
> android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native
> Method) 12-26 09:47:41.394: W/System.err(704):    at
> android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:882)
> 12-26 09:47:41.394: W/System.err(704):    at
> android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:493)
> 12-26 09:47:41.394: W/System.err(704):    at
> android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
> 12-26 09:47:41.404: W/System.err(704):    at
> android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
> 12-26 09:47:41.404: W/System.err(704):    at
> android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
> 12-26 09:47:41.414: W/System.err(704):    at
> android.database.sqlite.SQLiteDatabase.executeSql(SQLiteDatabase.java:1663)
> 12-26 09:47:41.414: W/System.err(704):    at
> android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1594)
> 12-26 09:47:41.414: W/System.err(704):    at
> com.survey.management.activity.MainActivity$RequestForSiteMenuFields.getSiteMenuFieldsData(MainActivity.java:295)
> 12-26 09:47:41.414: W/System.err(704):    at
> com.survey.management.activity.MainActivity$RequestForSiteMenuFields.doInBackground(MainActivity.java:277)
> 12-26 09:47:41.434: W/System.err(704):    at
> com.survey.management.activity.MainActivity$RequestForSiteMenuFields.doInBackground(MainActivity.java:1)
> 12-26 09:47:41.434: W/System.err(704):    at
> android.os.AsyncTask$2.call(AsyncTask.java:287) 12-26 09:47:41.444:
> W/System.err(704):    at
> java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
> 12-26 09:47:41.454: W/System.err(704):    at
> java.util.concurrent.FutureTask.run(FutureTask.java:137) 12-26
> 09:47:41.454: W/System.err(704):  at
> android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230) 12-26
> 09:47:41.454: W/System.err(704):  at
> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
> 12-26 09:47:41.504: W/System.err(704):    at
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
> 12-26 09:47:41.567: W/System.err(704):    at
> java.lang.Thread.run(Thread.java:856) 12-26 09:47:41.654:
> W/System.err(704): java.io.FileNotFoundException:
> /mnt/sdcard/taplaw.log: open failed: EACCES (Permission denied) 12-26
> 09:47:41.664: W/System.err(704):  at
> libcore.io.IoBridge.open(IoBridge.java:416) 12-26 09:47:41.664:
> W/System.err(704):    at
> java.io.FileOutputStream.<init>(FileOutputStream.java:88) 12-26
> 09:47:41.674: W/System.err(704):  at
> com.survey.management.util.ExceptionHandler.logException(ExceptionHandler.java:55)
> 12-26 09:47:41.684: W/System.err(704):    at
> com.survey.management.activity.MainActivity$RequestForSiteMenuFields.getSiteMenuFieldsData(MainActivity.java:319)
> 12-26 09:47:41.684: W/System.err(704):    at
> com.survey.management.activity.MainActivity$RequestForSiteMenuFields.doInBackground(MainActivity.java:277)
> 12-26 09:47:41.684: W/System.err(704):    at
> com.survey.management.activity.MainActivity$RequestForSiteMenuFields.doInBackground(MainActivity.java:1)
> 12-26 09:47:41.704: W/System.err(704):    at
> android.os.AsyncTask$2.call(AsyncTask.java:287) 12-26 09:47:41.704:
> W/System.err(704):    at
> java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
> 12-26 09:47:41.714: W/System.err(704):    at
> java.util.concurrent.FutureTask.run(FutureTask.java:137) 12-26
> 09:47:41.724: W/System.err(704):  at
> android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230) 12-26
> 09:47:41.724: W/System.err(704):  at
> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
> 12-26 09:47:41.724: W/System.err(704):    at
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
> 12-26 09:47:41.724: W/System.err(704):    at
> java.lang.Thread.run(Thread.java:856) 12-26 09:47:41.734:
> W/System.err(704): Caused by: libcore.io.ErrnoException: open failed:
> EACCES (Permission denied) 12-26 09:47:41.744: W/System.err(704):     at
> libcore.io.Posix.open(Native Method) 12-26 09:47:41.744:
> W/System.err(704):    at
> libcore.io.BlockGuardOs.open(BlockGuardOs.java:110) 12-26
> 09:47:41.754: W/System.err(704):  at
> libcore.io.IoBridge.open(IoBridge.java:400) 12-26 09:47:41.775:
> W/System.err(704):    ... 12 more 12-26 09:47:41.775: W/System.err(704):
> android.database.sqlite.SQLiteException: unrecognized token:
> "[Ljava.lang.String;@413777e0);" (code 1): , while compiling: INSERT 
> INTO
> menu_fields(ID,menu_id,field_type_id,c4w_code,field_label,field_values,date_created,date_modified,is_required,is_static,field_order)
> VALUES ([Ljava.lang.String;@413777e0); 12-26 09:47:41.785:
> W/System.err(704):    at
> android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native
> Method) 12-26 09:47:41.785: W/System.err(704):    at
>   android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:882)
> 12-26 09:47:41.785: W/System.err(704):    at
> android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:493)
> 12-26 09:47:41.794: W/System.err(704):    at
> android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
> 12-26 09:47:41.794: W/System.err(704):    at
> android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
> 12-26 09:47:41.804: W/System.err(704):    at
> android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
> 12-26 09:47:41.804: W/System.err(704):    at
> android.database.sqlite.SQLiteDatabase.executeSql(SQLiteDatabase.java:1663)
> 12-26 09:47:41.814: W/System.err(704):    at
> android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1594)
> 12-26 09:47:41.824: W/System.err(704):    at
> com.survey.management.activity.MainActivity$RequestForSiteMenuFields.getSiteMenuFieldsData(MainActivity.java:295)
> 12-26 09:47:41.824: W/System.err(704):    at
> com.survey.management.activity.MainActivity$RequestForSiteMenuFields.doInBackground(MainActivity.java:277)
> 12-26 09:47:41.824: W/System.err(704):    at
> com.survey.management.activity.MainActivity$RequestForSiteMenuFields.doInBackground(MainActivity.java:1)
> 12-26 09:47:41.824: W/System.err(704):    at
> android.os.AsyncTask$2.call(AsyncTask.java:287) 12-26 09:47:41.824:
> W/System.err(704):    at
> java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
> 12-26 09:47:41.834: W/System.err(704):    at
> java.util.concurrent.FutureTask.run(FutureTask.java:137) 12-26
> 09:47:41.844: W/System.err(704):  at
> android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230) 12-26
> 09:47:41.844: W/System.err(704):  at
> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
> 12-26 09:47:41.844: W/System.err(704):    at
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
> 12-26 09:47:41.854: W/System.err(704):    at
> java.lang.Thread.run(Thread.java:856)

1 个答案:

答案 0 :(得分:1)

尝试如下所示:

        String[] getSiteMenuFieldsData_Str_Array = getSiteMenuFieldsData_String
                .split("<br />");
        Log.i("getSiteMenuFieldsData_Str_Array:", ""
                + getSiteMenuFieldsData_Str_Array);

        for (int i = 0; i < getSiteMenuFieldsData_Str_Array.length; i++) {
            Log.i("getParametersData_Str_Array :",
                    getSiteMenuFieldsData_Str_Array[i].toString());
            String[] str = getSiteMenuFieldsData_Str_Array[i].split("[|]");
            StringBuilder tempQuery = new StringBuilder(
                    "INSERT  INTO menu_fields(ID,menu_id,field_type_id,c4w_code,field_label,field_values,date_created,date_modified,is_required,is_static,field_order) "
                            + "VALUES (");
            for (String s : str) {
                if (s.length() > 0)
                    tempQuery.append(s + ",");
            }
            tempQuery.deleteCharAt(tempQuery.lastIndexOf(","));
            tempQuery.append(");");
            String query = tempQuery.toString();
            Log.i("query result menu_fields:", "" + query);