OP-BTS Device Script Interpreter Guide: JSON

pika_cjson Module

API

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:...

class Null(cJSON):

def __init__(self):...

class True_(cJSON):

def __init__(self):...

class False_(cJSON):

def __init__(self):...

class Bool(cJSON):

def __init__(self,bolean:int):...

class Number(cJSON):

def __init__(self,num:float):...

class String(cJSON):

def __init__(self,string:str):...

class Raw(cJSON):

def __init__(self,raw:str):...

class Array(cJSON):

def __init__(self):...

class Object(cJSON):

def __init__(self):...

class StringReference(cJSON):

def __init__(self,string:str):...

class ObjectReference(cJSON):

def __init__(self,child:cJSON):...

class ArrayReference(cJSON):

def __init__(self,child:cJSON):...

Examples

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()

test2.py

import pika_cjson

data1 = "{\"data\":{\"validTime\":28800,\"token\":\"3E6EA1D907B9CFEB6AB1DECB5667E4A7\"},\"success\":true,\"resultCode\":\"0000\"} "
a = pika_cjson.Parse(data1)
a.print()

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()

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)

test1.py

import pika_cjson

data1 = '{"data":{"validTime":28800,"token":"3E6EA1D907B9CFEB6AB1DECB5667E4A7"},"success":true,"resultCode":"0000"}'
a = pika_cjson.Parse(data1)
a.print()

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()

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()