Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #30166
| Path | csiph.com!2.eu.feeder.erje.net!feeder.erje.net!1.eu.feeder.erje.net!news.albasani.net!.POSTED!not-for-mail |
|---|---|
| From | Stefan Weiss <krewecherl@gmail.com> |
| Newsgroups | comp.lang.javascript |
| Subject | Re: convert a string into a json object, |
| Date | Fri, 1 Apr 2016 10:49:32 +0200 |
| Organization | albasani.net |
| Lines | 40 |
| Message-ID | <ndlcms$ae5$1@news.albasani.net> (permalink) |
| References | <c8134afb-b7f5-4e2d-b3e6-90f8a3594544@googlegroups.com> <json-20160401033220@ram.dialup.fu-berlin.de> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=utf-8 |
| Content-Transfer-Encoding | 7bit |
| X-Trace | news.albasani.net BXopS6nB0q/oCeT32qikDrQF63ocN6IeaPxC6lWkII1LDSYgGdWpc5+gwknjG7IRW+RDaW4no9HqVVnQXj16FA== |
| NNTP-Posting-Date | Fri, 1 Apr 2016 08:49:32 +0000 (UTC) |
| Injection-Info | news.albasani.net; logging-data="OoW4bZTL+mkdoxd8UqveU20mjzXGfeZmw/jOpyaE0nq1SCm+fLCddIF39I8PxXcLainCma89UJlS1S40qmXSF6jPz9uGj2oSqZtjkgs/u7ahDLrL3FaXAMGW7O7CQ4v4"; mail-complaints-to="abuse@albasani.net" |
| User-Agent | Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.6.0 |
| In-Reply-To | <json-20160401033220@ram.dialup.fu-berlin.de> |
| Cancel-Lock | sha1:B0ho6sLFc6ib30JC1AYHqrPnqsg= |
| X-Enigmail-Draft-Status | N1110 |
| Xref | csiph.com comp.lang.javascript:30166 |
Show key headers only | View raw
Stefan Ram wrote:
> JRough <janis.rough@gmail.com> writes:
>> var string='Janis_SF_WebDev"\n"Debby_SJ_WebDev"\n"Stephanie_Fl_Recruite"\n"';
>
> main = function self()
Why not just `function main()`?
> { "use strict";
> const result = {};
Why an object instead of an array as container?
> const string = 'Janis_SF_WebDev"\n"Debby_SJ_WebDev"\n"Stephanie_Fl_Recruite"\n"';
> const row = string.split( '"\n"' );
> for( let i = 0; i < 3; ++i )
Hard-coding number of records...
> { const record = row[ i ].split( "_" );
> const person = {};
> person.name = record[ 0 ];
> person.city = record[ 1 ];
> person.job = record[ 2 ];
> result[ i ]= person; }
> console.log( JSON.stringify( result ));
> return result; };
>
> main();
>
> "{"0":{"name":"Janis","city":"SF","job":"WebDev"},"1":{"name":"Debby","city":
>"SJ","job":"WebDev"},"2":{"name":"Stephanie","city":"Fl","job":"Recruite"}}"
Off-topic... does anymody else find it counter-intuitive when most of the
variables are declared as "const"? I've seen this style recently in many
places, and it's technically correct, but for some reason I find it irritating.
- stefan
Back to comp.lang.javascript | Previous | Next — Previous in thread | 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