从Eclipse的XAMPP本地主机获取JSON提要 [英] Obtaining JSON feed from XAMPP localhost on Eclipse

查看:253
本文介绍了从Eclipse的XAMPP本地主机获取JSON提要的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是很新的Andr​​oid和编程和我试图写一个应用程序,会从互联网上下载一个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的网址是什么?因此,在本教程的 http://developer.android.com/training/基础/网络-OPS / connecting.html
我会说:

 网​​址URL =新的URL(HTTP://的locahost);

感谢您!


解决方案

1。设置后端(在你的案件PHP)

先制作一个项目文件夹里面的htdocs(取决于你在哪里安装了XAMPP)。


  1. 做一个与您的项目命名的文件夹。照片为〔实施例 API
    所以你将有 C:\\ XAMPP \\ htdocs中\\ API


  2. 接下来创建的index.php 文件项目中这样,那么你就会有这样的文件:结果
    C:\\ XAMPP \\ htdocs中\\ API \\的index.php


  3. 把你的PHP code成的index.php


  4. 通过访问测试你的后端 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.html would 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).

  1. make a folder named with your project.
    for examle API so you will have C:\xampp\htdocs\API

  2. next create index.php file inside that project so then you will have this file:
    C:\xampp\htdocs\API\index.php

  3. put your PHP code into that index.php

  4. 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提要的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆