8.30. pika_cjson 模块 API 文档
8.30.1. API
8.30.1.1. class cJSON(TinyObj):
def print(self)->str:...
def __del__(self):...
def __init__(self):...
def getObjectItem(self,string:str)->cJSON:...
def getArrayItem(self,index:int)->cJSON:...
def getArraySize(self)->int:...
def getType(self)->int:...
def getNext(self)->cJSON:...
def getPrev(self)->cJSON:...
def getChild(self)->cJSON:...
def getValueString(self)->str:...
def getValueInt(self)->int:...
def getValueDouble(self)->float:...
def getString(self)->str:...
def getValue(self)->any:...
def isInvalid(self)->int:...
def isFalse(self)->int:...
def isTrue(self)->int:...
def isBool(self)->int:...
def isNull(self)->int:...
def isNumber(self)->int:...
def isString(self)->int:...
def isArray(self)->int:...
def isObject(self)->int:...
def isRaw(self)->int:...
def addItemToArray(self,item:cJSON):...
def addItemToObject(self,string:str,item:cJSON):...
def Parse(value:str)->cJSON:...
8.30.1.2. class Null(cJSON):
def __init__(self):...
8.30.1.3. class True_(cJSON):
def __init__(self):...
8.30.1.4. class False_(cJSON):
def __init__(self):...
8.30.1.5. class Bool(cJSON):
def __init__(self,bolean:int):...
8.30.1.6. class Number(cJSON):
def __init__(self,num:float):...
8.30.1.7. class String(cJSON):
def __init__(self,string:str):...
8.30.1.8. class Raw(cJSON):
def __init__(self,raw:str):...
8.30.1.9. class Array(cJSON):
def __init__(self):...
8.30.1.10. class Object(cJSON):
def __init__(self):...
8.30.1.11. class StringReference(cJSON):
def __init__(self,string:str):...
8.30.1.12. class ObjectReference(cJSON):
def __init__(self,child:cJSON):...
8.30.1.13. class ArrayReference(cJSON):
def __init__(self,child:cJSON):...
8.30.2. Examples
8.30.2.1. test4.py
import pika_cjson
data1 = '{"data":{"requestSocialInsuranceFromYangCheng":"","authenticationComparison":"no","startupLogo":"4","cardType":"00,01,02,03,04","synfromhis":"no","alarmThresholdValue":"37.2","hospitalName":"jell","facediscernMode":"01","hospitalCode":"102"},"success":true,"resultCode":"0000","time":"2022-05-20 14:10:27","message":"ok"}'
a = pika_cjson.Parse(data1)
a.print()
8.30.2.2. test2.py
import pika_cjson
data1 = "{\"data\":{\"validTime\":28800,\"token\":\"3E6EA1D907B9CFEB6AB1DECB5667E4A7\"},\"success\":true,\"resultCode\":\"0000\"} "
a = pika_cjson.Parse(data1)
a.print()
8.30.2.3. test5.py
import pika_cjson
data1 = "{\"data\":{\"requestSocialInsuranceFromYangCheng\":\"\",\"authenticationComparison\":\"no\",\"startupLogo\":\"4\",\"cardType\":\"00,01,02,03,04\",\"synfromhis\":\"no\",\"alarmThresholdValue\":\"37.2\",\"hospitalName\":\"余杭农贸市场\",\"facediscernMode\":\"01\",\"hospitalCode\":\"102\"},\"success\":true,\"resultCode\":\"0000\",\"time\":\"2022-05-20 14:10:27\",\"message\":\"操作成功\"} "
a = pika_cjson.Parse(data1)
a.print()
8.30.2.4. test7.py
import pika_cjson as cjson
root = cjson.Object()
root.addItemToObject('name', cjson.String('mculover666'))
root.addItemToObject('age', cjson.Number(22))
root.addItemToObject('weight', cjson.Number(55.5))
address = cjson.Object()
address.addItemToObject('country', cjson.String('China'))
address.addItemToObject('zip-code', cjson.String('111111'))
root.addItemToObject('address', address)
skill = cjson.Array()
skill.addItemToArray(cjson.String('c'))
skill.addItemToArray(cjson.String('Java'))
skill.addItemToArray(cjson.String('Python'))
root.addItemToObject('skill', skill)
root.addItemToObject('student', cjson.False_())
root.print()
# data1 = "{"data":{"name":"11"}}"
# data1 = "{"data":{"token":"3E6EA1D907B9CFEB6AB1DECB5667E4A7","resultCode":"0000"},"resultCode":"0000"}"
#data1 = '{"data":{"requestSocialInsuranceFromYangCheng":"","authenticationComparison":"no","startupLogo":"4","cardType":"00,01,02,03,04","synfromhis":"no","alarmThresholdValue":"37.2","hospitalName":"jell","facediscernMode":"01","hospitalCode":"102"},"success":true,"resultCode":"0000","time":"2022-05-20 14:10:27","message":"ok"}'
#data1 = '{"data":{"validTime":28800,"token":"3E6EA1D907B9CFEB6AB1DECB5667E4A7"},"success":true,"resultCode":"0000"}'
# data1 = "{"data":{"jjj":"","333":"no","startupLogo":"4","cardType":"00,01,02,03,04","synfromhis":"no","alarmThresholdValue":"37.2","hospitalName":"jell","facediscernMode":"01","hospitalCode":"102"},"success":true,"resultCode":"0000","time":"2022-05-20 14:10:27","message":"ok"}"
#data1 = "{\"data\":{\"requestSocialInsuranceFromYangCheng\":\"\",\"authenticationComparison\":\"no\",\"startupLogo\":\"4\",\"cardType\":\"00,01,02,03,04\",\"synfromhis\":\"no\",\"alarmThresholdValue\":\"37.2\",\"hospitalName\":\"余杭农贸市场\",\"facediscernMode\":\"01\",\"hospitalCode\":\"102\"},\"success\":true,\"resultCode\":\"0000\",\"time\":\"2022-05-20 14:10:27\",\"message\":\"操作成功\"} "
#data1 = '{"sites": [{ "name":"Google", "info":[ "Android", "Google 搜索", "Google 翻译" ] }],"arraytest":{"test1":["c", "Java", "Python"],"test2":["c2", "Java2", "Python2"]},"data":{"requestSocialInsuranceFromYangCheng":"","authenticationComparison":"no","startupLogo":"4","cardType":"00,01,02,03,04","synfromhis":"no","alarmThresholdValue":"37.2","hospitalName":"余杭农贸市场","facediscernMode":"01","hospitalCode":"102"},"success":"true","resultCode":"0000","time":"2022-05-20 14:10:27","message":"操作成功"}'
data1 = '{"sites": [{ "name":"Google", "info":[ "Android", "Google search", "Google translation" ] },{ "name":"Runoob", "info":[ "ciniao jiaoc", "ciniao tool", "ciniao wechat" ] },{ "name":"Taobao", "info":[ "taobao", "shopping" ] }],"arraytest":{"test1":["c", "Java", "Python"],"test2":["c2", "Java2", "Python2"]},"data":{"requestSocialInsuranceFromYangCheng":"","authenticationComparison":"no","startupLogo":"4","cardType":"00,01,02,03,04","synfromhis":"no","alarmThresholdValue":"37.2","hospitalName":"余杭农贸市场","facediscernMode":"01","hospitalCode":"102"},"success":"true","resultCode":"0000","time":"2022-05-20 14:10:27","message":"操作成功"}'
a = cjson.Parse(data1)
a.print()
success = a.getObjectItem("success")
success.print()
value = success.getValueString()
print(value)
data = a.getObjectItem("data")
ret = data.isNull()
if ret == 0:
startupLogo = data.getObjectItem("startupLogo")
startupLogo.print()
startupLogovalue = startupLogo.getValueString()
print(startupLogovalue)
else:
print("data is null")
sites = a.getObjectItem("sites")
sites_num = sites.getArraySize()
for i in range(0, sites_num):
sites_item = sites.getArrayItem(i)
print("-------sites array ------")
# sites_item.print()
name = sites_item.getObjectItem("name")
namevalue = name.getValueString()
print(namevalue)
print("-------sites array info------")
info = sites_item.getObjectItem("info")
info_num = info.getArraySize()
print(info_num)
for j in range(0, info_num):
info_item = info.getArrayItem(j)
# print(info_item)
# info_item.print()
infodata = info_item.getValueString()
print(infodata)
8.30.2.5. test1.py
import pika_cjson
data1 = '{"data":{"validTime":28800,"token":"3E6EA1D907B9CFEB6AB1DECB5667E4A7"},"success":true,"resultCode":"0000"}'
a = pika_cjson.Parse(data1)
a.print()
8.30.2.6. test6.py
import pika_cjson
data1 = '{"array33":["c","Java","Python"],"data":{"requestSocialInsuranceFromYangCheng":"","authenticationComparison":"no","startupLogo":"4","cardType":"00,01,02,03,04","synfromhis":"no","alarmThresholdValue":"37.2","hospitalName":"余杭农贸市场","facediscernMode":"02","hospitalCode":"102"},"success":true,"resultCode":"0000","time":"2022-05-20 14:10:27","message":"操作成功"}'
a = pika_cjson.Parse(data1)
a.print()
8.30.2.7. test3.py
import pika_cjson as cjson
root = cjson.Object()
root.addItemToObject('name', cjson.String('mculover666'))
root.addItemToObject('age', cjson.Number(22))
root.addItemToObject('weight', cjson.Number(55.5))
address = cjson.Object()
address.addItemToObject('country', cjson.String('China'))
address.addItemToObject('zip-code', cjson.String('111111'))
root.addItemToObject('address', address)
skill = cjson.Array()
skill.addItemToArray(cjson.String('c'))
skill.addItemToArray(cjson.String('Java'))
skill.addItemToArray(cjson.String('Python'))
root.addItemToObject('skill', skill)
root.addItemToObject('student', cjson.False_())
root.print()