Hi, I’m having problem on loading a json response from a REST API. I cannot load the records into the queue because of a 1 record that have seems to be an RTF field. Here is the sample response.
Sample_Response.txt (32.3 KB)
I also tried pasting this on https://www.capesoft.com/jFilesCode and copied the structure it generated but still cannot be loaded into queue. Is there another way to load a json with RTF? I am currently using jFiles 3.12. Thanks
What is the error you are getting?
What is the structure of the queue?
Have you tried using the code from the Capesoft link you posted?
Can you show us your code?
For the error, honestly I don’t how to get the error since the Error property that is written in the jFiles documentation is not available.
The structure of my queue is this:
My code on the PageReceived is this:
I tried removing the specific record with the RTF field from the json response. It and it loaded to my queue with the code I used. But with raw response, nothing is loaded.
Hello @Romuald
Can you check the response are you getting from the API you are calling?
Try saving the response and see what you getting there first.
self.ThisPage.SaveFIle(‘.\api_response.txt’)
there is a sample of the response in his first msg.
Thanks @jslarve I’m aware of that. What I’m looking for is the real answer of a call to the API.
I was able to load the data provided by @Romuald without problems using the structure created by the Capesoft tool and using a StringTheory object to simulate the self.ThisPage…
st.Start()
st.LoadFile('.\Sample_Response.txt')
json.start()
json.SetTagCase(jf:CaseAsIs)
json.SetSaveBlankStringsAsNull(true)
json.SetDontSaveBlankArrayValues(true)
json.Load(QStocks,st) ! Load From a StringTheory object
I even change this field to a StringTheory like @Romuald has and the data still load
furtherDescription &StringTheory,NAME(‘furtherDescription | stringtheory’)
Sometimes happens to me that I think my structures are wrong, when in reality the server is answering with an specific http error because of a malformed request or server is unavailable.
Hi. The response from the API is the file I 1st shared. I just called the RemoveHeader then saved it to a file. Do you want the response with the header?
No, is ok. That confirms you are getting a response then.
Can you please copy and paste your entire structure definition to make tests in my side?The screenshot makes it a bit difficult to replicate.
Ok here it is.
Queue_Structure.txt (2.5 KB)
And my example still works fine with your structure. The only thing I haven’t tested in my API calls is the self.RemoveHeader() you are running after the CLEAR(gResult).
Not sure if that may or not change something, never had to do that to load data from API calls.
How about running that after trying to load the JSON, or for the sake of testing, comment those lines out?
I tried. But still not work for me. What i have done is I created a new project(.app) and with that it works. Then I tried creating a new procedure inside the same .app I am working with, it still not working. What is confusing is only on that .app this thing is not working, I only got success when I deleted the RTF record.
So the code is working in one app, but not another?
Do you get any warnings when you compile the not-working app?
Yes. Working for a fresh created app. Then I created another procedure that does the exact process as the first one, but the by the use of my self created template for sending and receiving from API. When I run it, it does not load to the queue. And then I deleted my second procedure again since I suspected it that it affects the first procedure. But this time it does not load to the queue even the procedure is again alone in the app. Then again I tried to modify the response removing the RTF field value and it successfully loaded to the queue.
When I’m compiling I do not get any warning or error.
myutil.tpl (22.7 KB)
So you have a custom template generating custom code.
Have you inspected the generated code to see where it differs from the working example you have?
Yes my template generates the exact codes that is working. But all good now. I just rolled back my jFiles from 3.12 to 3.09. I just found that the PC I was testing is using the older version of jFiles. In 3.12 it doesn’t load.
That’s not my definition of “all good”!
And what it is? As long as it works for now. I will just wait for new release of jFiles or if anyone can give me the proper code that works with the latest version.
With the test I did, I used JFiles version 3.11
Now, you mentioned you had JFiles 3.12. Im curious to know. Did you updated the String Theory template as well?
Version 3.12 - 8 April 2025
Update: Handle \uxxxx encoded values in the JSON before loading string.
Requires StringTheory 3.73 or later