Hi everyone. I'm using the Newtonsoft JSON library in NAV2016 C/AL to format a JSON web request. The code is straightfoward:
JsonTokenWriter := JsonTokenWriter.JTokenWriter;
JsonTokenWriter.WriteStartObject; //curly open {
CreateJSONAttribute('name','Shawn Ippotle');
CreateJSONAttribute('company','Shippo');
CreateJSONAttribute('street1','215 Clayton St.');
CreateJSONAttribute('street2','');
CreateJSONAttribute('city','San Francisco');
CreateJSONAttribute('state','CA');
CreateJSONAttribute('zip','94117');
CreateJSONAttribute('country','US');
CreateJSONAttribute('phone','+1 555 341 9393');
CreateJSONAttribute('email','shippotle@goshippo.com');
CreateJSONAttribute('is_residential','True');
CreateJSONAttribute('metadata','Customer ID 123456');
JSONTokenWriter.WriteEndObject;
JsonObject := JsonTokenWriter.Token;
The function "CreateJSONAttribute" is simple:
LOCAL CreateJSONAttribute(AttributeName : Text;Value : Variant)
JSONTokenWriter.WritePropertyName(AttributeName);
JSONTokenWriter.WriteValue(FORMAT(Value));
The resulting JSON object is truncated in the middle of one of the fields (the "email" field above):
{ "name": "Shawn Ippotle", "company": "Shippo", "street1": "215 Clayton St.", "street2": "", "city": "San Francisco", "state": "CA", "zip": "94117", "country": "US", "phone": "+1 555 341 9393", "email": "shippotle@goship
This is about 240 characters long (if I delete the CRLF characters, it's 230).
If I create a shorter string by ending the code before the "email" token), it terminates the JSON string correctly:
{ "name": "Shawn Ippotle", "company": "Shippo", "street1": "215 Clayton St.", "street2": "", "city": "San Francisco", "state": "CA", "zip": "94117", "country": "US", "phone": "+1 555 341 9393" }
I've tried several other techniques, like using the JSONMgt codeunit and building the JSON string directly, with the same truncated result.
Has anyone encountered this? Any solutions?
Thanks
Answers
I dumped the JSON contents into a BigText variable instead, and all is good