More

JSON String From VB.NET to Javascript over 100,000 characters


I have a string of properly formatted JSON from a VB.NET function that I am trying to pass to JavaScript where I can convert it into an OpenLayers vector layer. The string can be variable length, sometimes as small as 5,000 characters and sometimes as long as 40,000,000 characters.

Here is a small example of the JSON:

"{"type":"FeatureCollection","features":[{"type":"Feature","geometry":{"type":"MultiPolygon","coordinates":[[[[-79.546437887619277,41.450810394091974],[-79.546373336415854,41.450878338383419],[-79.546186240728744,41.450930517576978],[-79.546030161587709,41.451004424821683],[-79.546437887619277,41.450810394091974]]]]},"properties":{"tract":11001180000000,"stand_num":"11001180000006","acres":0.585540920000}},… etc.

If the string is less than 100,000 characters I can successfully send it to my JavaScript function as a normal string variable OR as a serialized variable, can successfully read it as GeoJSON, and add the features to my OpenLayers map using the normal OpenLayers GeoJSON methods. The following JavaScript takes the VB.NET serialized string and adds it to the map;

var geojson_format = new OpenLayers.Format.GeoJSON(); var vector_layer = new OpenLayers.Layer.Vector("query_POSTGIS"); var parsedJSON = JSON.parse(outputStr); alert(geojson_format.isValidType(parsedJSON, "FeatureCollection")); var geoJsonStr = geojson_format.read(parsedJSON, "FeatureCollection"); vector_layer.addFeatures(geoJsonStr);

This code works great until I get to the 100,000 character limit. Any suggestions on how to make this work with strings over 100,000 characters?


I was able to solve the issue. It appears that in .NET there is a limit to how long a string that is serialized can be and you must explicitly declare a maxJsonLength in your Web.config. I was able to solve the problem by adding the following to my Web.config:

   


Watch the video: JavaScript Tip: Using fetch to Load a JSON File (October 2021).