0

一定のチャンク化されたJSON応答を受信する必要がある状況があります。応答を受信するたびに、JSONを解析して、操作の現在のステータスでUIを更新する必要があります。

各応答を個別に受信し、応答の受信が完了するまで情報をUIにポストバックする簡単な方法を見つけることができません。

誰かがこれに光を当てることができれば、私は感謝するでしょう!

http呼び出しを行う101の異なる方法があります。応答を読み取るための正しい方法を備えた正しい方法が必要です。

-編集-これに追加するだけです。私が抱えている問題は、JSONデータを読み取っていないことです。各データチャンクを個別に取得し、各チャンク間でUIにポストバックしています–NathofGod27秒前編集

        DefaultHttpClient http_client = new DefaultHttpClient();
        HttpGet httpGet = new HttpGet(url);
        HttpResponse response = http_client.execute(httpGet);

        StatusLine statusLine = response.getStatusLine();
        int statusCode = statusLine.getStatusCode();
        HttpEntity entity = response.getEntity();

        InputStream in = entity.getContent();
        StringBuffer out = new StringBuffer();
        byte[] b = new byte[4096];
        int n =  in.read(b);
        out.append(new String(b, 0, n));        
        String resultdata = out.toString();

JSONの例

 23a
{"header":{"status":{"code":0,"desc":"Ok"},"sessionId":"3olpgjktvj0a52dbim6lk8hvet"},"summary":{"status":{"code":0,"desc":"Ok"},"inProgess":18,"errored":0},"storeItems":[{"storeItemId":"4ff41f0bdc6d34b3daaf4d8a","name":"Mcvities Digestive 250G","quantity":1,"itemPrice":0.89,"totalPrice":0.89,"recipeIngredients":[{"name":"250 g/8¾oz digestive biscuits, crushed","amount":1.0,"recipe":{"url":"http://www.bbc.co.uk/food/recipes/baileysandchocolatec_72293","title":"Baileys and chocolate cheesecake"}}],"status":{"code":3101,"desc":"Store item send to supermarket Ok"}}]}
3c1
{"header":{"status":{"code":0,"desc":"Ok"},"sessionId":"3olpgjktvj0a52dbim6lk8hvet"},"summary":{"status":{"code":0,"desc":"Ok"},"inProgess":17,"errored":0},"storeItems":[{"storeItemId":"4ff41f0bdc6d34b3daaf4d8a","name":"Mcvities Digestive 250G","quantity":1,"itemPrice":0.89,"totalPrice":0.89,"recipeIngredients":[{"name":"250 g/8¾oz digestive biscuits, crushed","amount":1.0,"recipe":{"url":"http://www.bbc.co.uk/food/recipes/baileysandchocolatec_72293","title":"Baileys and chocolate cheesecake"}}],"status":{"code":3101,"desc":"Store item send to supermarket Ok"}},{"storeItemId":"4ff41a73dc6d34b3daaf46da","name":"Rachels Organic Unsalted Butter 250G","quantity":1,"itemPrice":1.65,"totalPrice":1.65,"recipeIngredients":[{"name":"100 g/3½oz butter","amount":0.4,"recipe":{"url":"http://www.bbc.co.uk/food/recipes/baileysandchocolatec_72293","title":"Baileys and chocolate cheesecake"}}],"status":{"code":3101,"desc":"Store item send to supermarket Ok"}}]}
550
{"header":{"status":{"code":0,"desc":"Ok"},"sessionId":"3olpgjktvj0a52dbim6lk8hvet"},"summary":{"status":{"code":0,"desc":"Ok"},"inProgess":16,"errored":0},"storeItems":[{"storeItemId":"4ff41f0bdc6d34b3daaf4d8a","name":"Mcvities Digestive 250G","quantity":1,"itemPrice":0.89,"totalPrice":0.89,"recipeIngredients":[{"name":"250 g/8¾oz digestive biscuits, crushed","amount":1.0,"recipe":{"url":"http://www.bbc.co.uk/food/recipes/baileysandchocolatec_72293","title":"Baileys and chocolate cheesecake"}}],"status":{"code":3101,"desc":"Store item send to supermarket Ok"}},{"storeItemId":"4ff41a73dc6d34b3daaf46da","name":"Rachels Organic Unsalted Butter 250G","quantity":1,"itemPrice":1.65,"totalPrice":1.65,"recipeIngredients":[{"name":"100 g/3½oz butter","amount":0.4,"recipe":{"url":"http://www.bbc.co.uk/food/recipes/baileysandchocolatec_72293","title":"Baileys and chocolate cheesecake"}}],"status":{"code":3101,"desc":"Store item send to supermarket Ok"}},{"storeItemId":"4ff417c0dc6d34b3daaf28d3","name":"Menier Milk Chocolate Patissier 100G","quantity":1,"itemPrice":1.0,"totalPrice":1.0,"recipeIngredients":[{"name":"100 g/3½oz grated chocolate","amount":1.0,"recipe":{"url":"http://www.bbc.co.uk/food/recipes/baileysandchocolatec_72293","title":"Baileys and chocolate cheesecake"}}],"status":{"code":3101,"desc":"Store item send to supermarket Ok"}}]}
4

1 に答える 1

0
int n = in.read(b);
while(n>0){
    out.append(new String(b, 0, n);
    n = in.read(b);
}

String resultData = out.toString();
于 2012-09-13T00:18:26.347 に答える