var jsonstr = '{"desc":"OK","status":1000,"data":{"wendu":"34","ganmao":"各项气象条件适宜,发生感冒机率较低。但请避免长期处于空调房间中,以防感冒。","forecast":[{"fengxiang":"东风","fengli":"3-4级","high":"高温 35℃","type":"多云","low":"低温 27℃","date":"22日星期一"},{"fengxiang":"东风","fengli":"微风级","high":"高温 34℃","type":"多云","low":"低温 26℃","date":"23日星期二"},{"fengxiang":"东风","fengli":"微风级","high":"高温 35℃","type":"多云","low":"低温 27℃","date":"24日星期三"},{"fengxiang":"东风","fengli":"微风级","high":"高温 34℃","type":"多云","low":"低温 26℃","date":"25日星期四"},{"fengxiang":"东北风","fengli":"3-4级","high":"高温 33℃","type":"阴","low":"低温 25℃","date":"26日星期五"}],"yesterday":{"fl":"3-4级","fx":"北风","high":"高温 33℃","type":"雷阵雨","low":"低温 27℃","date":"21日星期日"},"aqi":"53","city":"常州"}}'
var list = new Function("return" + jsonstr)()
//html代码随便拼凑成需要的格式就行了
var htmlstr = "<ul style='border:1px solid #aaccff height:100px width:600px'> <li> 状态码:"
+ list.status + "</li> <li> 日期:"
+ list.data.yesterday.date + "</li> <li> 地址:"
+ list.data.city + "</li> <li> 预测风向:"
+ list.data.forecast[0].fengxiang + "</li> </ul>"
document.getElementById("id").innerHTML = htmlstr
}
import java.io.BufferedReaderimport java.io.File
import java.io.FileInputStream
import java.io.FileNotFoundException
import java.io.FileOutputStream
import java.io.FileWriter
import java.io.IOException
import java.io.InputStream
import java.io.InputStreamReader
/**
* java读写文件
* 读取d:/1.txt文件内容,写入f:/text.txt文件中.
*
* 写入文件换行用fw.write("\r\n")
* 或者fw.write("\n")
* @author young
*
*/
public class FileWriterTest {
// 读写文件
public static void rwFile(){
FileWriter fw = null
BufferedReader br = null
try {
// 定义FileWriter对象,关联文件f:\text.txt,用来向文件写内容
fw = new FileWriter("f:\\text.txt", true)
// 定义bufferedReader对象,用来读取d:\1.txt文件内容
br = new BufferedReader(new InputStreamReader(
new FileInputStream("d:\\1.html"), "UTF-8"))
String line = null
// 每次读取一行内容,循环读取,读到文件末尾结束
while ((line = br.readLine()) != null) {
System.out.println("文件内容: " + line)
fw.write(line)
// 刷新缓冲流,
fw.flush()
}
// 关闭I/O流
br.close()
} catch (FileNotFoundException e) {
e.printStackTrace()
} catch (IOException e) {
e.printStackTrace()
} finally {
if (fw != null) {
try {
fw.close()
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace()
}
}
}
}
public static void main(String[] args) {
rwFile()
}
}
把json返回的数据显示到html页面上的代码如下:
html中写姓名:<span id="username"></span>
js中写:
$(function () {
$.ajax({
type: "post",
url: "你后台返回json的页面地址",
dataType: "json",
data: {"operation":"getsiteroomname","bigcatid":bigcatid},//传递到后台页面的参数,没有就不要了
contentType: "application/x-www-form-urlencodedcharset=utf-8",
success: function(data) {
console.log(data)//将返回的值打印出来看看,然后你就知道怎么用了,可能如data.username
var xm=data.username
$("#username").text(xm)
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert('系统错误,联系管理员')
}
})
}
知识延展:
超文本标记语言, 标准通用标记语言下的一个应用。
“ 超文本 ”就是指页面内可以包含图片、 链接,甚至音乐、 程序等非文字元素。
超文本标记语言的结构包括 “头”部分(英语:Head)、和“主体”部分(英语:Body),其中“头”部提供关于网页的信息,“主体”部分提供网页的 具体内容。