|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- program testjson
- use json_module
- use RedisInterface
- use iso_c_binding, only: c_null_char,c_char
- integer::n_children
- logical :: is_found
- character(len=100),allocatable::redisOutput
- type(json_file) :: jsonfile
- type(json_value),pointer :: jsonroot,pval
- type(json_core) :: json
- character(len=:),allocatable::name
- integer::simulationStatus,simulationSpeed
-
-
- ! call initConnection("config-remote.json")
- ! call getData(redisContent)
- ! print *,len(redisContent)," bytes read from redis"
- ! open(1,file="redisContent.json",status="REPLACE")
- ! write(1,"(A)") redisContent
- ! close(1)
- ! call jsoncore%initialize()
- ! call jsoncore%deserialize(jsonvalue,redisContent)
- redisOutput = '{"status":1,"speed":10}'
- print *,"redisOutput=",redisOutput
- call jsonfile%initialize()
- call jsonfile%deserialize(redisOutput)
- ! call jsonfile%get("speed",simulationSpeed,is_found)
- ! if ( .not. is_found ) print *,"speed Not Found"
- ! call jsonfile%get("status",simulationStatus,is_found)
- ! if ( .not. is_found ) print *,"status Not Found"
- ! call jsonfile%get(pval,simulationSpeed)
- print *,"speed=",simulationSpeed
- print *,"status=",simulationStatus
- call jsonfile%json_file_get_root(jsonroot)
- call json%get(jsonroot,'status',pval)
- call json%get(pval,simulationStatus)
- call json%get(jsonroot,'speed',pval)
- call json%get(pval,simulationSpeed)
- print *,"speed=",simulationSpeed
- print *,"status=",simulationStatus
- call json%destroy(jsonroot)
- ! call jsonfile%load_file('redisContent.json'); if (jsonfile%failed()) stop
- ! call jsonfile%json_file_get_root(jsonvalue)
-
- ! call jsoncore%info(jsonvalue, n_children=n_children)
- ! print *,"n_children =",n_children
- ! call jsoncore%info(jsonvalue, name=name)
- ! print *,"name = ",name
- ! call json%initialize(allow_duplicate_keys=.false.)
- ! call json%create_object(p,'') !create the root
- ! call json%add(p,'year',1805) !add some data
- ! call json%add(p,'year',2000) !add some data
- ! call json%add(p,'value',1.0) !add some data
- ! call json%print(p,'test.json') !write it to a file
- ! call json%destroy(p) !cleanup
-
- end program testjson
|