티스토리 뷰

SWDesk

[Android, PHP] JSON Test

inhae 2021. 7. 7. 23:26

<on Android>

    private void TestJSON(){
        FormBody.Builder formBody = new FormBody.Builder();
        JSONObject jsonObject = new JSONObject();
        ArrayList<String> models = new ArrayList<String>();
        models.add("Model#1");
        models.add("Model#2");
        models.add("Model#3");
        try {
            jsonObject.put("JSONList", models);
        }catch(Exception e){
            return;
        }

        Log.d("[Array Test String]", models.toString());
        String jsonString = jsonObject.toString();
        Log.d("[JSON Test String]", jsonString);

        try{
            //jsonInput.put("Value4", siteString);
            formBody.add("UserID", UserID);
            formBody.add("UserCode", UserCode);
            formBody.add("RequestType", "JSONTest");
            formBody.add("JSONList", jsonString);
        }catch(Exception e){
            return;
        }
        HttpRequestType = REQUEST_USERINFO;
        RequestBody requestBody = formBody.build();
        HttpResponseString = null;
        EnableAllButtons(false);
        SendHttpRequest(requestBody);
    }

 

<on PHP>

		echo "Testing JSON ...";
		$jsonString = $_POST["JSONList"];
		echo "[JSONString] ".$jsonString."<br>";
		$jsonList_ = json_decode($jsonString, true);
		$jsonString2 = $jsonList_['JSONList'];
		$jsonList2 = explode(",", $jsonString2);
		$jsonList3 = array();
		foreach($jsonList2 as $jsonItem){
			if($jsonItem[0] == "[") $jsonItem = substr($jsonItem, 1);
			$length = strlen($jsonItem);
			if($jsonItem[$length-1] == "]") $jsonItem = substr($jsonItem, 0, $length-1);
			$jsonItem = trim($jsonItem);
			$jsonList3[] = $jsonItem;
		}
		echo "[JSONList-3]".$jsonList3[2];
반응형

'SWDesk' 카테고리의 다른 글

인공지능 스타트업  (0) 2021.07.17
[PHP, Python] JSON Test  (0) 2021.07.10
[Python] Editing Images  (1) 2021.06.30
[Python] Download Google Images  (0) 2021.06.29
[Python] Sharing Google Spreadsheet  (0) 2021.06.29
반응형
250x250
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/01   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함