Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #30163
| Newsgroups | comp.lang.javascript |
|---|---|
| Date | 2016-03-31 19:12 -0700 |
| Message-ID | <c8134afb-b7f5-4e2d-b3e6-90f8a3594544@googlegroups.com> (permalink) |
| Subject | convert a string into a json object, |
| From | JRough <janis.rough@gmail.com> |
It does the first split into a 3 dim arr but it doesn't split those 3 strings up into the data for the jsonObject. Thanks.
<!DOCTYPE html>
<head>
<script>
var string='Janis_SF_WebDev"\n"Debby_SJ_WebDev"\n"Stephanie_Fl_Recruite"\n"';
function doJson(string){
var arr = string.split("\n");
for (i=0;i< 2;i++){
var str= arr[i].split("_");
var jsonObj= {};
jsonObj.name =str[0];
jsonObj.city= str[1];
jsonObj.job = str[2];
}
return jsonObj;
}
var myObj = doJson(string);
console.log(myObj);
</script>
</head>
<body>
</body>
</html>
Back to comp.lang.javascript | Previous | Next — Next in thread | Find similar | Unroll thread
convert a string into a json object, JRough <janis.rough@gmail.com> - 2016-03-31 19:12 -0700
Re: convert a string into a json object, Stefan Weiss <krewecherl@gmail.com> - 2016-04-01 10:42 +0200
Re: convert a string into a json object, JRough <janis.rough@gmail.com> - 2016-04-01 17:32 -0700
Re: convert a string into a json object, Stefan Weiss <krewecherl@gmail.com> - 2016-04-01 10:49 +0200
Re: convert a string into a json object, John Harris <niam@jghnorth.org.uk.invalid> - 2016-04-01 19:21 +0100
Re: convert a string into a json object, Aleksandro <aleksandro@gmx.com> - 2016-04-01 16:21 -0300
Re: convert a string into a json object, Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-04-01 20:36 +0100
Re: convert a string into a json object, Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-04-02 04:07 +0200
Re: convert a string into a json object, Aleksandro <aleksandro@gmx.com> - 2016-04-02 12:07 -0300
Re: convert a string into a json object, Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-04-02 17:36 +0200
Re: convert a string into a json object, Aleksandro <aleksandro@gmx.com> - 2016-04-02 21:01 -0300
Re: convert a string into a json object, Scott Sauyet <scott@sauyet.com> - 2016-04-02 20:40 +0000
Re: convert a string into a json object, Stefan Weiss <krewecherl@gmail.com> - 2016-04-02 01:18 +0200
Re: convert a string into a json object, John Harris <niam@jghnorth.org.uk.invalid> - 2016-04-02 11:29 +0100
Re: convert a string into a json object, Scott Sauyet <scott@sauyet.com> - 2016-04-02 20:30 +0000
Re: convert a string into a json object, JRough <janis.rough@gmail.com> - 2016-04-01 11:32 -0700
Re: convert a string into a json object, Stefan Weiss <krewecherl@gmail.com> - 2016-04-02 00:51 +0200
Re: convert a string into a json object, Aleksandro <aleksandro@gmx.com> - 2016-04-02 12:03 -0300
Re: convert a string into a json object, Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-04-02 03:48 +0200
Re: convert a string into a json object, Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-04-02 04:25 +0200
csiph-web