So I'm building an email module in to my software. Beyond essential headers I've decided to simply keep the $headers array and store it in a TEXT column called headers. Basically the only time this JSON stored data will be retrieved is when someone does an AJAX request to look at the extended headers (not loaded by default). I'll pull it from MySQL, convert the JSON to a PHP array and iterate over each of the header fields. So in other words I won't be selectively choosing any parts of the array inside of the JSON (inside of the database), merely as a string to be handled by PHP. In this case is using TEXT data type appropriate? I'm also open to other advice.
Sure, that's fine. You could also serialize and unserialize the array instead of using JSON; I don't think there's any reason to convert it to a JavaScript object if it's only ever going to be used in PHP.
Related
If you send plain Json formatted un-serialized text from a web api and have it be de-serialized in a C# function using the jsonConvert.DeserializeObject functional? I have a co-worker who created a web api in the cloud and he sends plain text formatted to look like un-serialized Json which I try to use C# functionality to Deserialize but when I try to convert what is sent into Model classes it fails. I am telling him that the C# JsonConvert.SerializeObject must be used or it won't work. Can someone help clarify this with me?
Your colleague is right. JSON strings need to be de-serialized to turn them into objects.
Moreover, the things you call "plain text formatted to look like JSON" are JSON strings. JSON is plain text (in UTF8, with syntax rules).
Let's say you have some data structure in your program that you want to send over the network. The network can only send series of bytes, so whatever your structure was, you need to turn it into that -- you need to serialize it. JSON is one way of doing that, e.g.
'{"example": "some data"}'
is a string containing JSON. It is serialized, it's just a string of bytes to send over the network.
On the receiving end, you need to deserialize it back into some data structure, some type of hash map or dictionary or whatever it's called in C# probably.
If what you try "fails", you could ask a much more specific question showing what you tried with what data and how exactly it failed.
I have seen some posts but not getting any example for this use case, here is a link which I have referred to this. I have read some blogs also but all was in vain.
It is mostly the same as using JSON, except that instead of using a serialized JSON string you will send a binary array of bytes (meaning it's important your content-type is binary/octet-stream, not utf-8 or whatever).
This has examples on how to construct and access the byte array (make sure to select JavaScript or whichever language you're using): http://google.github.io/flatbuffers/flatbuffers_guide_tutorial.html
I am trying to generate a report page in my APEX application, using the data obtained from a REST service response.
I added a new RESTful webservice reference and sepecified a JSON output.
Then I've generated a query/report page, but this is what's being currently displayed:
Instead I want the report to display the contents of data field on the JSON response (A single row with various columns and values)
Is there any straight forward way to show each response element and field on its row and column instead of a single column and row with the whole response, like there is with XML RESTful responses?
Consider whether another output type may be more handy. If you're putting out JSON and expect to handle it in PLSQL, then you do need to realize that PLSQL does not handle that natively.
Want to handle the rest response as json in plsql? Then look into some PLSQL libraries/projects that may do this:
http://reseau.erasme.org/pl-sql-library-for-JSON?lang=en
http://sourceforge.net/projects/pljson/
Then print out the returned HTML through HTP.P calls.
Though honestly, if you want to stick with plsql you would be much better off using XML as a return type, since you can then use all the xml goodies in the database. Though simply spitting out some html structure may not be quite too interesting (but I digress).
Or call the rest service through an ajax call from javascript, and handle the object there. After all, JSON is Javascript Object Notation and should be perfect for javascript, right? Then simply inject your html somewhere in the document. Ideally you would set up a region as a container for this.
I have a server and I need to upload files along with some fields from the client to the server. I have currently been using standard multipart/form-data.
I have found however that using multipart/form-data is not ideal. Objects on my server may have other objects nested within them, and thus are represented as a JSON object with other JSON objects embedded within.
I would like for the client to start making POST/PUT requests using a JSON representation exactly like it would expect in a GET request to the server, in a REST-ful manner. This way I don't have to flatten the fields which might be nested a couple layers within the JSON object in order to use multipart/form-data.
Problem is, JSON doesn't represent binary data. Multipart/form-data doesn't seem to have a way to represent fields nested within the values of other fields. But it does have much better handling of file-uploads.
I am at a loss for how to design this. Should I just have the client upload JSON with the fields encoded in base64, and take the 25% hit? Or should I have the JSON object being represented as some sort of "json" variable in a Multipart/form-data request, and have the binary files to be uploaded as another variable?
Should I just have the client upload JSON with the fields encoded in
base64, and take the 25% hit?
The hit will be 33% since 4/3=1.33.
Or should I have the JSON object being represented as some sort of
"json" variable in a Multipart/form-data request, and have the binary
files to be uploaded as another variable?
This should work.
You might also consider this approach: send all files using multipart, then get some identificators of files as a response. Put this identificators in your json and send it anyway you like. This approach might be beneficial if you have many scenarios in which you send files: you might always send them to the server with the same request, then get their identificators; after that do with them what you like.
I am trying to send a generated PDF file (Apache FOP) to the client. I know this can be done by writing the array to the response stream and by setting the correct content type, length and so on in the servlet. My problem is that the whole app was built based on the idea that it will only receive/send JSON. In the servlet's service() method, I have this:
response.setContentType("application/json");
reqBroker.process(request, response);
RequestBroker is the class who processes the JSON (jackson processor), everything is generic and I cannot change it. On top of this, I have to receive the JSON from the request correctly, to access the data and generate my pdf. So those two lines are necessary. But when I send the response, I need to have another content type so that the pdf is displayed correctly in the browser.
So far, I am able to send the byte array as part of the JSON, but then I don't know how to display the array as PDF on the client (if smth like this is even possible).
I would like some suggestions on how can I send my pdf and set the right header, without messing with the JSON. Thanks.
JSON and byte arrays don't mix.
Instead, you should create an <iframe> and point it to a URL that returns a raw PDF.
Take a look here:How to send pdf in json, it lists couple of approaches that you can consider. The easiest way is to convert the binary data into string by using Base64 compression. In C#, this would mean a call to Convert.FromBase64String. However this has space overhead as Base64 compression means around +33% more memory. If you can get away with it, this is the least complicated solution. in case additional size is an issue you can think about zipping it up.