Hi,
I've compiled a static library for Json-c include files that ship with Freebasic. Compiled(GCC) source code corresponds to same Json-c version as stated in include files.
Eigil
Hi Eigil,
I am looking at json libraries and see that you have provided a static interface to the json-c. I simply copied your file to the same folder as my sample source code and added this to the top of the file:
#include once "json-c/json.bi"
#inclib "JsonWin32"
The exe appears to compile but that is where I seem to get stuck. I am not confident that the static code is added to the exe because when I try to output the results of the following get version function I get a compile error saying that the function could not be found.
? json_c_version_num
Maybe I'm missing something simple? I have not used static libraries with FB so I could use a little help. Maybe a simple example of how you are using this code?
Hi Paul,
Haven't looked at JSON since last February so I had to refresh a bit. Here's a small code sample. I have my static library libjsonwin32.a in ... \inc\json-c folder.
Code compiles and works on my pc.
Eigil
#include once "windows.bi"
#Include once "file.bi"
#include ONCE "string.bi"
'json
#include "C:\FreeBasic\FreeBASIC-1.07.0\inc\json-c\json.bi"
#include "C:\FreeBasic\FreeBASIC-1.07.0\inc\json-c\printbuf.bi"
#inclib "jsonwin32"
dim jOuter as json_object ptr = json_object_new_object()
dim jBody as json_object ptr = json_object_new_object()
json_object_object_add(jOuter,"argument", jbody)
'' 'Creating json strings*/
dim jstring1 as json_object ptr = json_object_new_string("#XXXX.IMS.Compliance.ValidateSimulatedOrdersArgument")
dim jstring2 as json_object ptr = json_object_new_string("#Collection(String)")
'' 'Form the json object*/
'' 'Each of these is like a key value pair*/
json_object_object_add(jBody,"@odata.type", jstring1)
json_object_object_add(jBody,"OrderIds@odata.type", jstring2)
'create an json object array with containg OrderIDS
dim jOrdersID as json_object ptr = json_object_new_array()
json_object_array_add(jOrdersID, json_object_new_string("Order_1"))
json_object_array_add(jOrdersID, json_object_new_string("Order_2"))
dim jOrderarr as json_object ptr = jOrdersID
'add the array to the body
json_object_object_add(jBody,"OrderIds",jOrderarr )
'print the object
print *json_object_to_json_string_ext(jBody,JSON_C_TO_STRING_PRETTY )
sleep
end
Thanks Eigil !!!
I really appreciate you taking the time to help me out with this one. I now have it working correctly on my end. :-)
Here is the code that I am using thanks to Eigil's example:
' json-c test
#include once "json-c/json.bi"
#include once "json-c/printbuf.bi"
' Copy the libJsonWin32.a file to either same folder as your source code/exe or
' to the \lib folder of your GCC toolchain.
#inclib "JsonWin32"
dim jOuter as json_object ptr = json_object_new_object()
dim jBody as json_object ptr = json_object_new_object()
json_object_object_add(jOuter,"argument", jbody)
'' 'Creating json strings*/
dim jstring1 as json_object ptr = json_object_new_string("#XXXX.IMS.Compliance.ValidateSimulatedOrdersArgument")
dim jstring2 as json_object ptr = json_object_new_string("#Collection(String)")
'' 'Form the json object*/
'' 'Each of these is like a key value pair*/
json_object_object_add(jBody,"@odata.type", jstring1)
json_object_object_add(jBody,"OrderIds@odata.type", jstring2)
'create an json object array with containg OrderIDS
dim jOrdersID as json_object ptr = json_object_new_array()
json_object_array_add(jOrdersID, json_object_new_string("Order_1"))
json_object_array_add(jOrdersID, json_object_new_string("Order_2"))
dim jOrderarr as json_object ptr = jOrdersID
'add the array to the body
json_object_object_add(jBody,"OrderIds",jOrderarr )
'print the object
print *json_object_to_json_string_ext(jBody,JSON_C_TO_STRING_PRETTY )
sleep
end
Paul,
I was a bit too triggerhappy with copy paste.
If you replace the *json_object_to_json_string_ext(jBody,JSON_C_TO_STRING_PRETTY ) line with
print *json_object_to_json_string_ext(jOuter,JSON_C_TO_STRING_PRETTY )
you'll see the nested structure better.
\E