On Wed, 30 Jan 2019 at 16:41, fugee ohu <fugee...@gmail.com> wrote: > > > > On Wednesday, January 30, 2019 at 9:45:03 AM UTC-5, Colin Law wrote: >> >> On Wed, 30 Jan 2019 at 13:48, fugee ohu <fuge...@gmail.com> wrote: >> > >> >> >> >> Show us what puts parsed_obj["results"] gives. If it is long then >> >> from the start up to where productID occurs. >> >> >> >> Colin >> > >> > >> > {"productId"=>32970292001, "sellerId"=>235696817, "oriMinPrice"=>"US >> > $50.00", "oriMaxPrice"=>"US $50.00", "productTitle"=>"Paid function", >> > "minPrice"=>"US $50.00", "maxPrice"=>"US $50.00", "orders"=>"1", >> > "productImage"=>"//ae01.alicdn.com/kf/HTB10AX7aPLuK1Rjy0Fhq6xpdFXa5.jpg", >> > "productDetailUrl"=>" ... >> >> Are you absolutely sure that is what parsed_obj["results"] is? >> Frankly I think you are mistaken. >> Looking at the original source you posted which had >> "results":[{"productId":32755997022,"... >> suggests that actually parsed_obj["results"] should be >> [ {"productId"=>32970292001,...},{...}] >> >> Colin > > > Unparsed response looks like this > > /**/myscript.js({"success":true,"code":0,"results":[{"productId":32962770119, > ... > ,"itemEvalTotalNum":0}],"finished":false,"page":1,"pageSize":20,"postback":"9954eca0-4297-4d1f-bada-a5c3b131214c","pin":"gps-id=pcDetailLeftTrendProduct&scm=1007.13438.100207.0&scm_id=1007.13438.100207.0&scm-url=1007.13438.100207.0&pvid=778c79a8-9092-483e-92cb-f393856b0565"}); > So if I'm gonna use this approach I have to gsub out everything up to the > first [{ after the last }] > As you can see I was trying another approach as well, need to learn both, > substituting the original callback script for myscript.js I can write a > function instead of using JSON.parse but I wanna be able to do it both ways
Am I right in saying that parsed_obj is actually an array as I suggested? If so then do you not know how to access the elements of the array? 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-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/CAL%3D0gLsnsMENQ6i_TsBxFzKNVe9L1Q-d5X2Bz5PEV0mNOHyYdQ%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.