您的代碼會工作的API調用,如果服務器響應將是一個JSON文件。響應目前是一個HTML文件,使混亂,如果查看它的網絡瀏覽器(同樣的內容是雙向的網絡瀏覽器,並記錄在一個OkHttpClient
實例):
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Testing Connection Page</title>
</head>
<body>
{"all":[{"id":"0","Country":"Brazil","Language":"Portuguese","Topic":"HandWashing","Title":"How to Wash Your Hands","Video":"AKA1_Fante_Ghana_HandWashing_Final.3gp","Videolight":"AKA1_Fante_Ghana_HandWashing_Final_Light.3gp","Description":"Washing hands is the best way to prevent the spread of germs and diseases. Dirty hands can carry pathogenic germs that can sicken a person or spread diseases to others. Microorganisms such as bacteria, viruses, parasites, fungi and various chemicals can enter our bodies directly when we touch our face, eyes, nose or mouth or may enter indirectly, when our dirty hands stain surfaces touched by others or where food is prepared. The habit of washing hands with soap and water constitutes the first line of defense against the spread of many diseases, from the common cold or diarrhea to more serious illnesses such as meningitis, influenza or hepatitis as well as many other diseases. This 2-D animation describes the importance of hand washing.","Image":"HandWashing.jpg"},{"id":"1","Country":"Kenya","Language":"Swahili","Topic":"SGComposting3D","Title":"Survival Gardening: How to Create Compost (3D)","Video":"SW_Swahili_Kenya_SGComposting3D_Final.3gp","Videolight":"SW_Swahili_Kenya_SGComposting3D_Final_Light.3gp","Description":"Compost can be used to improve the quality of your soil. You can use plant materials, animal manure and kitchen scraps to create compost. Compost will add nutrients and organic matter to your soil. This animation explains the process of creating and storing compost.","Image":"SGComposting3D.jpg"}],"Language":["Portuguese","Swahili"],"Topic":["HandWashing","SGComposting3D"],"Country":["Brazil","Kenya"]}
</body>
</html>
您應該只是修復mobileApp.php
腳本並刪除所有與JSON結構無關的內容。如果響應Content-Type
標題將被設置爲JSON MIME類型:What is the correct JSON content type?將會很好。
你是如何解析json?共享代碼 – AwaisMajeed
與轉換器-GSON作爲這樣的:'改造改型=新Retrofit.Builder() .baseUrl( 「http://sawbo-illinois.org」) .addConverterFactory(GsonConverterFactory.create()) .build( ); ServiceAPI服務= retrofit.create(ServiceAPI.class); final致電
as this ????這是哪裏? – AwaisMajeed