Similar:
var array = $('textarea').val().split(/\n|\r/);
So, you get an array of JavaScript object, not a JSON string. If you want a JSON string, you can use the jquery-the json plugin , and then follow these steps:
var jsonString = $.toJSON( $('textarea').val().split(/\n|\r/) );
And if you want an object, not an array, encoded in the JSON, do the following:
var o = {}; $( $('textarea').val().split(/\n|\r/) ).each(function(i){ o[i] = this; }); var jsonString = $.toJSON(o); val () split (/ \ n |.. \ R /)) .each (function (i) { var o = {}; $( $('textarea').val().split(/\n|\r/) ).each(function(i){ o[i] = this; }); var jsonString = $.toJSON(o);
source share