import json
aItem = {}
aItem["id"] = "2203"
aItem["title"] = "title"
aItem["subTitle"] = "sub title"
bItem = {}
bItem["id"] = "2842"
bItem["title"] = "b标题"
bItem["subTitle"] = "b副标题"
bItem["content"] = "内容"
bItem["list"] = ["a", "a 2", "b", "bb"]
aJson = json.dumps(aItem)
bJson = json.dumps(bItem, ensure_ascii=False)
print(aItem)
print(aJson)
print(bJson) {'id': '2203', 'title': 'title', 'subTitle': 'sub title'}
{"id": "2203", "title": "title", "subTitle": "sub title"}
{"id": "2842", "title": "b标题", "subTitle": "b副标题", "content": "内容", "list": ["a", "a 2", "b", "bb"]} jsonList = [] jsonList.append(aItem) jsonList.append(bItem) jsonArr = json.dumps(jsonList, ensure_ascii=False) print(jsonArr)
[{"id": "2203", "title": "title", "subTitle": "sub title"}, {"id": "2842", "title": "b标题", "subTitle": "b副标题", "content": "内容"}] 这一个JSON字符串可以在Android Studio中利用插件GsonFormat转换得到相应对象。
以上就是实例解析Python3.x对JSON的操作的详细内容,更多请关注Gxl网其它相关文章!
查看更多关于实例解析Python3.x对JSON的操作的详细内容...
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://haodehen.cn/did84492