0

次の形式の出力があります。

 {"status":"07\/09\/201207:16||heythisisatestquestion||AndyesIreallyansweredthisquestiontoo-||07\/09\/201207:10||heythisistestquestion||ThisismyresponsetoyourTESTquestion-yes,Ireallyansweredyou.:-)||07\/09\/201206:29||sos||SOSagain-yes||07\/09\/201206:27||sos||SOSagain-yes||07\/09\/201205:05||test||Yes,respondingtothisTEST-yes,it'sworking","phone":"xxxxxxxxx"}

私がやりたいことは、|| で区切られた各値を取得することです。配列

例:

 **07\/09\/201207:16 .. 07\/09\/201207:10 .. 07\/09\/201206:29**  should be in array date

 **heythisisatestquestion .. heythisistestquestion .. sos** should be in array question 

 **AndyesIreallyansweredthisquestiontoo .. ThisismyresponsetoyourTESTquestion .. Ireallyansweredyou** 

配列 Answers にある必要があります。キーワード || を一致させて各値を区切るにはどうすればよいですか。

4

2 に答える 2

1

まず、JSON を解析してステータス文字列を取得する必要があります。

次に、ステータス文字列を に沿って分割します"\\|\\|"。すなわち.split("\\|\\|")。そして、トークンを 3 つのグループに分けます。

ステータス テキストの形式が常に有効であると仮定すると、次のようになります。

 ArrayList<String> date = new ArrayList<String>();
 ArrayList<String> question = new ArrayList<String>();
 ArrayList<String> response = new ArrayList<String>();

 for (int i = 0; i < tokenArray.length / 3; i++) {
     date.add(tokenArray[i * 3]);
     question.add(tokenArray[i * 3 + 1]);
     response.add(tokenArray[i * 3 + 2]);
 }
于 2012-07-10T05:35:44.420 に答える
1

PHP を使用して JSON を生成している場合は、式を使用して爆発で同様の関数を見つけてから 、配列を送信するか、Java で送信できます。

    int count=0;
        String[] arr;
        arr=str.split("\\|\\|");
        for(int i=0,j=1,k=2;i<str.length;i+=3,j+=3,k+=3)
    {

    array1[count]=arr[i];
    array2[count]=arr[j];
    .....
    .....
count++;

    }
于 2012-07-10T05:51:35.307 に答える