我有我的Android Java代碼必須傳遞一些數組和一些多維數組到PHP服務器。不幸的是,我沒有訪問PHP服務器的權限。從Android到PHP傳遞數組和多維數組
這裏的PHP服務器API:
$result= array(
"username" => "admin",
"password" => "admin",
"hobbies" => array(
"1" => "science"
),
"skills" => array(
"1" => array(
"Boxing" => "Yes"
)
)
);
這裏是我的Android的Java代碼:
final String hobbies[] = {"science"};
final String skills[][] = {{"Boxing"},{"Yes"}};
@Override
protected Map<String, String> getParams() {
Map<String, String> jParams= new HashMap<String, String>();
JSONArray arrHobbies = new JSONArray();
JSONArray arrSkills = new JSONArray();
arrHobbies.put(hobbies[0]);
arrSkills.put(skills[0][0]);
jParams.put("username", "admin");
jParams.put("password", "admin");
jParams.put("hobbies",arrHobbies.toString();
jParams.put("skills",arrSkills.toString();
return jParams;
}};
然後,我用這個代碼來看看data've被髮送方式。
Log.d("Response : ", jParams.toString());
這表明這對Android日誌:
{password=admin, username=admin, hobbies=["science"], skills=[["275]]}
UPDATE 這裏的哈希值,當我調試代碼:
0 = {[email protected]} "hobbies" -> "{"1":"1"}"
1 = {[email protected]} "password" -> "admin"
2 = {[email protected]} "username" -> "admin"
3 = {[email protected]} "skills" -> "{"1":{"Boxing":"Yes"}}"
我永遠不會成功與溝通PHP服務器API。 請幫我看看我錯在哪裏或錯在哪裏。
它是什麼應該登錄?因爲那正在記錄你正在創建的內容?我懷疑你不理解什麼'技能[] []'實際上創造 –