lr100
lr100

Reputation: 600

JSON PHP to JSON Python

I am converting my php over to python.

In my php I have (this has always work with my iPhone app):

...
$profile = mysql_fetch_array($query_result, MYSQL_ASSOC);
$profile_json = array();
$profile_json[] = $profile;
echo json_encode(array('success' => 1, 'myProfile' => $profile_json));

I know have this in Python (doesn't seem to work with iPhone app):

...
profile = db_cursor.fetchone()
json_user_profile = json.dumps(profile)
json_obj= {'success': 1, 'myProfile': json_user_profile,}
self.response.out.write(json.dumps(json_obj))

I need my python to return exactly what my php was returning.

Anyone up to help? :)

Upvotes: 0

Views: 103

Answers (1)

dave
dave

Reputation: 64657

Pretty sure you need to change it to:

profile = db_cursor.fetchone()
json_obj= {'success': 1, 'myProfile': profile}
self.response.out.write(json.dumps(json_obj))

Otherwise you are double json encoding the profile

Upvotes: 1

Related Questions