Return json from python -


i have simple module in drupal expecting 4 values in json python script. believe python script collecting data need fine:

 # information easy via xpath html ids tree = etree.html(tree) make = tree.xpath('//div[@id="makedata"]')[0] model = tree.xpath('//div[@id="modeldata"]')[0] manufacture_year = tree.xpath('//div[@id="manufactureyeardata"]')[0] engine_size = tree.xpath('//div[@id="enginesizedata"]')[0] 

now need return data drupal module can catch this:

  // execute script , store output in variable $py_output = shell_exec($cmd);  // assuming output json string. $data = drupal_json_decode($py_output); 

i don't know python, searching around lead me try this:

return json.dumps({'make': make,                    'model': model,                    'year': year,                    'engine': engine}) 

that doesn't seem work. appreciated!


Comments

Popular posts from this blog

Winapi c++: DialogBox hangs when breaking a loop -

vb.net - Font adding using PDFsharp -

javascript - jQuery iScroll clickable list elements while retaining scroll? -