2
我想發送字符串數組到php由Json和檢索那裏。發送字符串數組到php
String[] Books = {"book1", "book2", "book3", "book4",..};
在JSON:
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>;
nameValuePairs.add(new BasicNameValuePair("books", Books));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
...
在PHP端:
$books = $_POST['books'];
$result = json_decode($books); // is this OK?
或者我可以用它象下面這樣?
$book1 = $result[0];
如果u發送的數據爲JSON然後u需要json_decode(),但行的數據沒有任何JSON格式化發佈數據將以數組形式。 –
我由json發送。問題是我不確定這種方法是否正確。是否是$ result和數組。 'nameValuePairs.add(new BasicNameValuePair(「books」,Books));'發送字符串數組的好方法或者我應該使用'nameValuePairs.add(new BasicNameValuePair(「books」,Books []));'here? –