AJAX

一 AJAX预备知识:json进阶

1.1 什么是JSON?

JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式。JSON用字符串来表示Javascript对象

请大家记住一句话:json字符串就是js对象的一种表现形式(字符串的形式)

既然我们已经学过python的json模块,我们就用它来测试下json字符串和json对象到底是什么

import json
i=10
s='hello'
t=(1,4,6)
l=[3,5,7]
d={'name':"yuan"}

json_str1=json.dumps(i)
json_str2=json.dumps(s)
json_str3=json.dumps(t)
json_str4=json.dumps(l)
json_str5=json.dumps(d)

print(json_str1)   #'10'
print(json_str2)   #'"hello"'
print(json_str3)   #'[1, 4, 6]'
print(json_str4)   #'[3, 5, 7]'
print(json_str5)   #'{"name": "yuan"}'
View Code

相关文章: