Welcome to 16892 Developer Community-Open, Learning,Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Is it possible to convert a json string (for e.g. the one returned from the twitter search json service) to simple string objects. Here is a small representation of data returned from the json service:

{
results:[...],
"max_id":1346534,
"since_id":0,
"refresh_url":"?since_id=26202877001&q=twitter",
.
.
.
}

Lets say that I somehow store the result in some variable, say, obj. I am looking to get appropriate values like as follows:

print obj.max_id
print obj.since_id

I've tried using simplejson.load() and json.load() but it gave me an error saying 'str' object has no attribute 'read'

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.9k views
Welcome To Ask or Share your Answers For Others

1 Answer

I've tried using simplejson.load() and json.load() but it gave me an error saying 'str' object has no attribute 'read'

To load from a string, use json.loads() (note the 's').

More efficiently, skip the step of reading the response into a string, and just pass the response to json.load().


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to 16892 Developer Community-Open, Learning and Share
...