I'm working with data via an IBM MQ call where a 0 is returned as +0.0 when this is serialized by ColdFusion 10 (10,0,11,285437) it results in invalid JSON and cannot be deserialized.
stPolicy = { "prem": "+0.0" };
serializedData = serializeJSON(stPolicy);
writeDump(isJSON(serializedData));
writeDump(deserializeJSON(serializedData));
This outputs NO for isJSON and an error when trying to deserialize JSON parsing failure at character 9:'+' in {"prem":+0.0}.
I'm able to work around this by replacing all +0 to 0, but I'm guessing this is a bug in ColdFusion. Has anyone else had this issue and implemented a better fix?
Bug report filed: Bug #3632972
Adobe has the bug listed as fixed in their bug database, but it has not yet been released. Here's the fix I came up with. Simply replace the +0 with 0
private string function serializeJSONFixCF10(required string serializedData) {
return replace(arguments.serializedData,'+0','0','all');
}
Related
in c# I validate a json with a json schema, using the library Newtonsoft.Json.
JsonSchema schema = JsonSchema.Parse(schemaJson);
JObject Json= JObject.Parse(json);
bool valid = Json.IsValid(schema);
It works fine, but the problem is that I don't understand where the errors occur in a simple way. My 'json' is only in one Line and I have a lot of property so it isn't immediate to find the position of the proprierty where the error occurs.
For example, I got the error:
'Invalid type. Expected String but got Null. Line 1, position 2221'
Is there a way to find the name of the property of my json where the error occurs using the library Newtonsoft.Json?
Thanks a lot
I have a stored proc that returns json. The proc works fine and when I call it in SSMS it returns a json object that I can click and see as valid json. When I call it through Visual Studio it does the same, and clicking into it and pressing return formats it nicely so it's readable (and not all on a single line). If I take the string and pass it back into the sql function IsJson, it also returns true, so I'm 100% confident that the json coming out of the proc is valid.
However, my frontend developer is unable to parse it, and it seems to boil down to something trying to convert it somewhere.
The json (as output from the proc) is:
{"APIResult":[{"ID":200,"Status_Message":"Success","Developer_Message":"Successful login for D56D10AC-3A74-42FC-8BB5-F783A6C0C556 33E4F907-F1E5-4F1B-8CA5-5521291E683A (AppID: (null)).","User_Message":"Successful login","User":[{"ID":"D56D10AC-3A74-42FC-8BB5-F783A6C0C556"}]}]}
Using Postman to hit the live API (or localhost) I get back the data I expect (as above) however, it wraps the entire thing in double quotes and escapes all the double quotes around each element, so I get:
"{\"APIResult\":[{\"ID\":200,\"Status_Message\":\"Success\",\"Developer_Message\":\"Successful login for D56D10AC-3A74-42FC-8BB5-F783A6C0C556 33E4F907-F1E5-4F1B-8CA5-5521291E683A (AppID: (null)).\",\"User_Message\":\"Successful login\",\"User\":[{\"ID\":\"D56D10AC-3A74-42FC-8BB5-F783A6C0C556\"}]}]}"
When I try to parse this in sql (using isjson) it returns false. However, parsing this same code though jsonlint.com interprets it as valid. Trying it through the parser my developer is using http://json.parser.online.fr throws it out as errors too.
At a push, I can tell my developer to strip the first and last characters and replace every \" with " but this seems a bit faffy.
Are there different interpretations of json? I've read that this is often caused by the calling app expecting a string that it needs to json-ify and because it's getting a json object it's json-ifying the json, but even if I force sql server to output the string as a string and not json, it still seems the same. SQL is definitely pushing it out correctly but whatever my developer is calling the api through returns the same format as postman, and doesn't like it. How can I ensure that what the calling code gets is what SQL is giving and not some weird interpretation?
#Tim Try to deserialize the output of stored procedure. Use JSonConvert.Derialize in C#
When creating a SuperObject from a string, it might happen that the string is no valid JSon.
Unfortunately the command SO doesn't raise an exception in that case.
I end up with a object where I THINK I can store data in, but the "stored" data goes nowhere and is lost.
example:
MySo:=SO('{}');
MySO.S['ok']:='test';
Memo1.Lines.Add(MySO.AsJSon(True, False));
MySo:=SO('');
MySO.S['fail']:='mimimi';
Memo1.Lines.Add(MySO.AsJSon(True, False)); // returns '""' ??!??
How can I check if the string was converted successfully into a valid and working SuperObject?
whorsyourdaddy's comment pointed into the right direction.
To be able to store INTO a JSon you need a stObject. You can check for that this way:
if not MySo.IsType(stObject) then raise....
I found a tutorial for server implementation in a game on this link:
http://unity-tutorials.blogspot.in/
I implemented the code for my server sending in the following data on the Login Section to my Server:
{"email":"rudi#mrpatch.co", "pass": "mrpatch"}
This server is implementing JSON and is giving the below response :
Receive response: "{\"status\":\"success\",\"data\":[{\"id\":\"1\",\"email\":\"rudi#mrpatch.co\",\"password\":\"mrpatch\",\"first_name\":\"Rudi\",\"last_name\":\"Ullon\",\"birth_date\":\"1981-03-20\",\"status\":\"1\"}]}"
There is a JSON parser script in this project, which returns System.string , this is being used by a parser in my other script LoginService.js
But while I am trying to store this in a Boo.Lang.Hash (hashtable) it gives me error in following code:
var parsed : Boo.Lang.Hash = JSONParse.JSONParse(httpResponse.text);
This is the Error message I am getting:
InvalidCastException: Cannot cast from source type to destination type.
LoginService+$sendLoginData$6+$.MoveNext () (at Assets/Scripts/StartMenu/LoginService.js:61)
I have tried saving it a Boo.Lang.Hash, as String etc. but nothing seems to be working.
if you have json you can do in this way.
var parsed : Boo.Lang.Hash = JSONParse.JSONParse(your json );
Oh boy...
You seem to have quite some conceptual issues with type casting and that's a far too broad topic (joke link). :P
The error message means you can't convert from String to that Hashtable through casting. You need a function to convert it for you or do it yourself.
The JSONParse you mentioned can actually do it:
var jsonData : json = json.fromString(httpResponse.text);
At least now you have jsonData.values which can be easily converted to a Hashtable...
But keep in mind "Hashtables" are obsolete and even the Unity Player will warn you about it. Read more.
you must use the JsonPare.js from source code on the demo.https://docs.google.com/file/d/0B0HipNssJJD-bEh0Wi1XeV9PSlE/edit
I'm using a custom object extended from fabric.Image in my canvas, as suggested in this answer. When I retrieve the json string from the server, I get odd errors when attempting to load it to the canvas:
var canvas = new fabric.Canvsd();
function loadCanvas(resp) {
// response object contains a data field
// that's essentialy a JSON string
var json = JSON.parse(resp.data);
canvas.loadFromDatalessJSON(json);
}
I get an odd printout to the console: Cannot call method 'setupState' of undefined (fabric.min.js: 1118). I tried replacing the call with canvas.loadFromJSON(json), and instead got a vague SyntaxError: Unexpected token o error. When I used a regular fabric.Image before the change suggested in the linked thread, this code worked fine. I fear this might be something I'm missing when I extended favric's Image class with aditional data. Thoughts?
After some search I saw a similar thread in the fabricjs google group. Turned out I messing up 3 things:
I was missing a fromObject() callback definition in a different location for another custom object I made (I had a couple).
I was using loadFromDatalessJSON() when I should have been using simply loadFromJSON().
I was parsing the json string into an actual JSON using JSON.parse(json) before passing it into the loadFromJSON() function, which expected a json string and handled the parsing internally.
Derp.