Output seems to stop right in the middle of the string?

Oct 10, 2010 at 1:37 PM

I'm  trying to serialize a form's fields into a JSON string, but the result I'm getting seems to cut off in the middle, it ends like this: "SupportsPrevalues":false,"RequiresScriptManager":false,"HideField

And that's it.. On another form, it ends in the middle of a word: DataF

What am I missing here? I'm probably overlooking something really obvious. This is the executed method:

 

        public string GetFormFields(string formGuid)
        {
            var json = "";
            using (var formStorage = new FormStorage())
            {
                var form = formStorage.GetForm(new Guid(formGuid));
                var ser = new JsonSerializer
                              {
                                  ReferenceLoopHandling = ReferenceLoopHandling.Error
                              };

                ser.Error += SerErrorHandler;

                using (var recordService = new RecordService(form))
                {
                    recordService.Open();

                    foreach (var field in recordService.Form.AllFields)
                    {
                        using (var ms = new MemoryStream())
                        using (var writer = new JsonTextWriter(new StreamWriter(ms)))
                        {
                            ser.Serialize(writer, field);
                            json += Encoding.Default.GetString(ms.ToArray());
                        }
                    }
                }
                return json;
            }
        }

 

 

Coordinator
Oct 10, 2010 at 9:38 PM

Flush the JsonTextWriter before calling GetString.

Oct 10, 2010 at 9:42 PM

Aaah, of course! Thanks James, worked like a charm.

Apr 27, 2012 at 12:48 PM

I am wondering why cannot it Flush the JsonTextWriter automatically?