On Saturday, December 29, 2018 at 2:12:33 AM UTC-5, Colin Law wrote:
>
>
>
> On Sat, 29 Dec 2018, 03:42 fugee ohu <fuge...@gmail.com <javascript:> 
> wrote:
>
>>
>>
>> On Friday, December 28, 2018 at 5:00:46 PM UTC-5, Colin Law wrote:
>>>
>>> On Fri, 28 Dec 2018 at 21:40, fugee ohu <fuge...@gmail.com> wrote: 
>>> > ... 
>>> > I think I just need to strip the leading 
>>> /**/jQuery18307882633047005491_1545805999753 from the result 
>>>  
>>> /**/jQuery18307882633047005491_1545805999753({"success":true,"code":0,"results":[{"productId":32817749905,
>>>  
>>>
>>> > Anyone can help with the regex? 
>>>
>>> If you can't work out the regex just find the position of the first { 
>>> and strip to there. 
>>>
>>> Colin 
>>>
>>
>> I gsub'd for the first  ({
>>
>>  json_data = res.body.gsub(/^.+\(\{/, "\(\{")
>> json = JSON.parse(json_data)
>> JSON::ParserError: 765: unexpected token at 
>> '({"success":true,"code":0,"results":[{"productId":32817
>>
>
>
> Look at the JSON spec again. What should the first char be?
>
> Colin
>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Ruby on Rails: Talk" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to rubyonrails-ta...@googlegroups.com <javascript:>.
>> To post to this group, send email to rubyonra...@googlegroups.com 
>> <javascript:>.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/rubyonrails-talk/007843ea-8793-46fb-ab40-bf63e55fb2bf%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/rubyonrails-talk/007843ea-8793-46fb-ab40-bf63e55fb2bf%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
The first character should be a curly bracket 
json_data = res.body.gsub(/^.+\{/, "\{").chop
json = JSON.parse(json_data)

JSON::ParserError: 765: unexpected token at 
'{\"pvid\":\"805ba4ee-6446-4148-ab0a-ff5e51c0ab24\",\"

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/74861111-d6f7-4752-b20c-ffc335da704d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to