您的代码会工作的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