Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #17389 > unrolled thread
| Started by | justaguy <lichunshen84@gmail.com> |
|---|---|
| First post | 2012-11-30 22:20 -0800 |
| Last post | 2012-12-01 07:43 -0800 |
| Articles | 4 — 2 participants |
Back to article view | Back to comp.lang.javascript
A simple regexp question justaguy <lichunshen84@gmail.com> - 2012-11-30 22:20 -0800
Re: A simple regexp question Stefan Weiss <krewecherl@gmail.com> - 2012-12-01 09:58 +0100
Re: A simple regexp question justaguy <lichunshen84@gmail.com> - 2012-12-01 07:35 -0800
Re: A simple regexp question justaguy <lichunshen84@gmail.com> - 2012-12-01 07:43 -0800
| From | justaguy <lichunshen84@gmail.com> |
|---|---|
| Date | 2012-11-30 22:20 -0800 |
| Subject | A simple regexp question |
| Message-ID | <6759f512-f267-4919-bbb9-8ab3450ecb30@c14g2000vbd.googlegroups.com> |
I have a json string that reads like this:
('partname':['Antenna'],'partdescription':['Sensor Systems Dual
Iridium Antenna;'])
The tool I'm using to parse json
JSON.parse(theString)
failed, complaining about unexpected character.
So, I wonder if I remove all the occurences of [' and '] would help.
I attempted
replace(/['/g,"")
but it failed.
What's wrong with the above global replace syntax?
Thanks in advance.
[toc] | [next] | [standalone]
| From | Stefan Weiss <krewecherl@gmail.com> |
|---|---|
| Date | 2012-12-01 09:58 +0100 |
| Message-ID | <k9cgr3$a43$1@news.albasani.net> |
| In reply to | #17389 |
On 2012-12-01 07:20, justaguy wrote:
> I have a json string that reads like this:
> ('partname':['Antenna'],'partdescription':['Sensor Systems Dual
> Iridium Antenna;'])
>
> The tool I'm using to parse json
> JSON.parse(theString)
> failed, complaining about unexpected character.
>
> So, I wonder if I remove all the occurences of [' and '] would help.
It would not, because those aren't the unexpected characters. JSON
strings are serializations of objects or arrays, and as such they always
start with "{" or "[", respectively. Strings values have to be in double
quotes.
The JSON syntax is very simple; take a look at the diagram on this page:
http://json.org/
The syntactically correct JSON form of your string would be
{"partname":["Antenna"],"partdescription":["Sensor Systems Dual
Iridium Antenna;"]}
(after removing the line break artifact).
Also note that your object contains arrays as values for partname and
partdescription. If that's not what you want, use strings instead:
{"partname":"Antenna","partdescription":"Sensor Systems Dual
Iridium Antenna;"}
The semicolon after Antenna looks unintentional, too, but I don't know
what you intend to do with the data.
> I attempted
> replace(/['/g,"")
> but it failed.
>
> What's wrong with the above global replace syntax?
"[" is a special character in regular expressions. If you want to use it
literally, you need to escape it:
str.replace(/\['/g, "");
- stefan
[toc] | [prev] | [next] | [standalone]
| From | justaguy <lichunshen84@gmail.com> |
|---|---|
| Date | 2012-12-01 07:35 -0800 |
| Message-ID | <ff0a5b25-834a-4b72-b133-f9ef214c45e5@y6g2000vbb.googlegroups.com> |
| In reply to | #17391 |
On Dec 1, 3:58 am, Stefan Weiss <krewech...@gmail.com> wrote:
> On 2012-12-01 07:20, justaguy wrote:
>
> > I have a json string that reads like this:
> > ('partname':['Antenna'],'partdescription':['Sensor Systems Dual
> > Iridium Antenna;'])
>
> > The tool I'm using to parse json
> > JSON.parse(theString)
> > failed, complaining about unexpected character.
>
> > So, I wonder if I remove all the occurences of [' and '] would help.
>
> It would not, because those aren't the unexpected characters. JSON
> strings are serializations of objects or arrays, and as such they always
> start with "{" or "[", respectively. Strings values have to be in double
> quotes.
>
> The JSON syntax is very simple; take a look at the diagram on this page:http://json.org/
>
> The syntactically correct JSON form of your string would be
>
> {"partname":["Antenna"],"partdescription":["Sensor Systems Dual
> Iridium Antenna;"]}
>
> (after removing the line break artifact).
>
> Also note that your object contains arrays as values for partname and
> partdescription. If that's not what you want, use strings instead:
>
> {"partname":"Antenna","partdescription":"Sensor Systems Dual
> Iridium Antenna;"}
>
> The semicolon after Antenna looks unintentional, too, but I don't know
> what you intend to do with the data.
>
> > I attempted
> > replace(/['/g,"")
> > but it failed.
>
> > What's wrong with the above global replace syntax?
>
> "[" is a special character in regular expressions. If you want to use it
> literally, you need to escape it:
>
> str.replace(/\['/g, "");
>
> - stefan
What you wrote makes lots of sense. Thanks.
I ended up with retrieving data from the JSON object (array) directly
(since I know its structure already). It's so much cleaner this way
rather than data parsing.
Another question,
How do I pass a parameter/value to a class if that's possible?
Not even sure if it's possible.
For instance, in this case.
instead of
id="partnumber2" class="autocomplete"
we'll have the following:
id="partnumber2" class="autocomplete?row=2"
If not, how do I accomplish the same thing?
That is, at the end of the class execution, I'd like to perform
another js function which needs a parameter and its value.
Many thanks.
[toc] | [prev] | [next] | [standalone]
| From | justaguy <lichunshen84@gmail.com> |
|---|---|
| Date | 2012-12-01 07:43 -0800 |
| Message-ID | <7cb8952e-ebd6-4786-b29f-ba20cce87092@k6g2000vbr.googlegroups.com> |
| In reply to | #17395 |
On Dec 1, 10:35 am, justaguy <lichunshe...@gmail.com> wrote:
> On Dec 1, 3:58 am, Stefan Weiss <krewech...@gmail.com> wrote:
>
>
>
>
>
>
>
>
>
> > On 2012-12-01 07:20, justaguy wrote:
>
> > > I have a json string that reads like this:
> > > ('partname':['Antenna'],'partdescription':['Sensor Systems Dual
> > > Iridium Antenna;'])
>
> > > The tool I'm using to parse json
> > > JSON.parse(theString)
> > > failed, complaining about unexpected character.
>
> > > So, I wonder if I remove all the occurences of [' and '] would help.
>
> > It would not, because those aren't the unexpected characters. JSON
> > strings are serializations of objects or arrays, and as such they always
> > start with "{" or "[", respectively. Strings values have to be in double
> > quotes.
>
> > The JSON syntax is very simple; take a look at the diagram on this page:http://json.org/
>
> > The syntactically correct JSON form of your string would be
>
> > {"partname":["Antenna"],"partdescription":["Sensor Systems Dual
> > Iridium Antenna;"]}
>
> > (after removing the line break artifact).
>
> > Also note that your object contains arrays as values for partname and
> > partdescription. If that's not what you want, use strings instead:
>
> > {"partname":"Antenna","partdescription":"Sensor Systems Dual
> > Iridium Antenna;"}
>
> > The semicolon after Antenna looks unintentional, too, but I don't know
> > what you intend to do with the data.
>
> > > I attempted
> > > replace(/['/g,"")
> > > but it failed.
>
> > > What's wrong with the above global replace syntax?
>
> > "[" is a special character in regular expressions. If you want to use it
> > literally, you need to escape it:
>
> > str.replace(/\['/g, "");
>
> > - stefan
>
> What you wrote makes lots of sense. Thanks.
> I ended up with retrieving data from the JSON object (array) directly
> (since I know its structure already). It's so much cleaner this way
> rather than data parsing.
>
> Another question,
> How do I pass a parameter/value to a class if that's possible?
> Not even sure if it's possible.
>
> For instance, in this case.
> instead of
> id="partnumber2" class="autocomplete"
> we'll have the following:
> id="partnumber2" class="autocomplete?row=2"
>
> If not, how do I accomplish the same thing?
> That is, at the end of the class execution, I'd like to perform
> another js function which needs a parameter and its value.
>
> Many thanks.
Oh, never mind the "pass a parameter/value to a class if that's
possible? " question, I've already solved the problem. Thanks anyway.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.javascript
csiph-web