问题描述
我是很新的Android和编程和我试图写一个应用程序,会从互联网上下载一个JSON饲料并在屏幕上显示出来。
所以我使用XAMPP我没有访问到服务器。从我的研究,我将不得不用PHP编写以下code,使其呼应JSON我的应用程序?
< PHP
回声\"{\"array\":[1,2,3],\"boolean\":true,\"null\":null,\"number\":123,\"object\":{\"a\":\"b\",\"c\":\"d\",\"e\":\"f\"},\"string\":\"Hello世界}
?>
然后在Eclipse中,我会不得不使应用程序的角度,以localhost的网址是什么?因此,在本教程的
我会说:
网址URL =新的URL(HTTP://的locahost);
感谢您!
1。设置后端(在你的案件PHP)
先制作一个项目文件夹里面的htdocs(取决于你在哪里安装了XAMPP)。
-
做一个与您的项目命名的文件夹。照片为〔实施例
API
所以你将有C:\\ XAMPP \\ htdocs中\\ API
-
接下来创建
的index.php
文件项目中这样,那么你就会有这样的文件:结果C:\\ XAMPP \\ htdocs中\\ API \\的index.php
-
把你的PHP code成的index.php
- 通过访问测试你的后端
HTTP://locahost/API/index.php
;它应该告诉你一个JSON恩codeD字符串。
2。改变你的API调用:
网址URL =新的URL(HTTP://locahost/API/index.php);
I'm quite new to android and programming and I am attempting to write an app that would download a JSON feed from the internet and display it on the screen.
I don't have access to a server so I'm using XAMPP. From my research, would I have to write the following code in PHP so that it will echo the JSON to my app?
<?php
echo "{"array":[1,2,3],"boolean":true,"null":null,"number":123,"object":{"a":"b","c":"d","e":"f"},"string":"Hello World"}"
?>
Then in Eclipse, would I have to make the url of the app point to "localhost"? Therefore, in the tutorial http://developer.android.com/training/basics/network-ops/connecting.htmlwould I say:
URL url = new URL(http://locahost);
Thank you!
1. Set up your backend(in your case PHP)
first make a project folder inside your htdocs.(depends where you installed xampp).
make a folder named with your project.
for examleAPI
so you will haveC:\xampp\htdocs\API
next create
index.php
file inside that project so then you will have this file:C:\xampp\htdocs\API\index.php
put your PHP code into that index.php
- test your back-end by accessing
http://locahost/API/index.php
; it should show you a json encoded string.
2. Change your API call:
URL url = new URL(http://locahost/API/index.php);
这篇关于从Eclipse的XAMPP本地主机获取JSON提要的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!