Comparing JSON Response with String in Python -


I am currently developing a filter for JSON responses. I am basically confused as to why the printing in truth is false as this is true in value code. .com / search / 1 / track.json? Q = "user_query = urllib.quote_plus (entry) url + = user_query feedback = urlopen (url) json_obj = json.load (feedback) print json.dumps (json_obj ['tracks'] [3] ['name']) # This "true" value = json.dumps (json_obj ['tracks'] [3] ['name']) "=" "print true_Value

in your pocket"

As you said, json.dumps (json_obj ['tracks'] [3] ['name'])

return "in your pocket" ..., while you are comparing it with the string without quotation marks.

I A simple test is done:

  print "//" + json.dumps (json_obj ['tracks'] [3] ['name']) "" // "print" // // " 

in your pocket it will print:

  //" in your pocket "// // in your pocket at //  

If you want to be true_value to be true you should do

  true = value = Json.dumps (json_obj ['tracks'] [3] ['name']) == "\" in your pocket \ ""  

Comments