OK here goes. The logic in the routine which is actually doing the modification to each individual JSON response looks like this:
if str(objctTyp) == 'user':
rspnsdata['name'] = lstobjct['name']
rspnsdata['id'] = lstobjct['id']
rspnsdata['name'] = lstobjct['name']
rspnsdata['id'] = lstobjct['id']
The routine which is doing this is receiving parameter data that looks like this when printed in string format in the windows command prompt window:
rspnsdata=
{
u'participations': [],
u'page_views':
{
u'2015-02-05T00:00:00-06:00': 1,
u'2015-03-02T23:00:00-06:00': 1,
u'2015-01-24T19:00:00-06:00': 1,
u'2015-02-08T13:00:00-06:00': 1,
u'2015-01-28T19:00:00-06:00': 1,
u'2015-01-20T19:00:00-06:00': 1,
u'2015-02-19T10:00:00-06:00': 2,
u'2015-02-21T17:00:00-06:00': 1,
u'2015-02-02T13:00:00-06:00': 1,
u'2015-02-16T13:00:00-06:00': 1,
u'2015-02-01T23:00:00-06:00': 2,
u'2015-02-03T12:00:00-06:00': 2
}
u'participations': [],
u'page_views':
{
u'2015-02-05T00:00:00-06:00': 1,
u'2015-03-02T23:00:00-06:00': 1,
u'2015-01-24T19:00:00-06:00': 1,
u'2015-02-08T13:00:00-06:00': 1,
u'2015-01-28T19:00:00-06:00': 1,
u'2015-01-20T19:00:00-06:00': 1,
u'2015-02-19T10:00:00-06:00': 2,
u'2015-02-21T17:00:00-06:00': 1,
u'2015-02-02T13:00:00-06:00': 1,
u'2015-02-16T13:00:00-06:00': 1,
u'2015-02-01T23:00:00-06:00': 2,
u'2015-02-03T12:00:00-06:00': 2
}
}
lstobjct=
{
'name': 'Brennan Kennedy',
'id':'8202'
}
'name': 'Brennan Kennedy',
'id':'8202'
}
objctTyp=
user
Hope this helps.
Thanks.
Henry
On Monday, March 9, 2015 at 1:04:12 PM UTC-5, ke1g wrote:
If it's not the basics, then you haven't provided enough information to allow someone to spot the problem. If you post the code that is performing the modification, someone may be able to spot the issue.On Mon, Mar 9, 2015 at 1:50 PM, Henry Versemann <fence...@gmail.com> wrote:--Yes Id did do that. The problems I seem to be having only seem to happen whenever I modify the data before sending it. For many other requests that I'm sending and not modifying the data, before I send them back to the client I have no problems and everything is apparently parsed out ok by the javascript on the client side.Thanks.Henry
On Monday, March 9, 2015 at 12:42:23 PM UTC-5, ke1g wrote:Did you remember to set the content type of your response to application/json?On Mon, Mar 9, 2015 at 1:18 PM, Henry Versemann <fence...@gmail.com> wrote:--First to be clear up front let me say that I'm using Django1.7, Python 2.7.8, and the requests (Requests: HTTP for Humans) library version2.4.3 to build the application mentioned below.I have an application which needs to be able to process a single AJAX request as a series of related sub-requests sent to a remote API. Each sub-request response comes back in JSON format. The first of these sub-requests returns a list of students in a particular course, and the returned response data is a list containing student objects all in JSON format. A Django view code then strips outs the 'name' and 'id' of each student object in the list and builds it as an entry in another python list to be used later(I'm using "json.loads()" to get to successfully the original JSON data returned in each reasponse). Then once this list is built it is passed to another view which then submits a different request, for each student "id", in the newly built list, to the same API, to return all student information (related to a particular course-id which is also passed in this second request), for the current student. Then the returned course-student information, for this second request, is also returned in JSON format.Everything up to this point works perfectly, but it is at this point that I believe my process is going wrong, when I try to modify the JSON data returned, form the second series of requests.My modifications seem to work, on the server side(and I'm using json.dumps() to serialize my data into JSON format), and all of my data seems to be present when I print it in my command prompt window right before sending it back to the client, as part of an HttpResponse. Then when I try to access some of the data using javascript/jQuery once its been sent back to the client then some of the "jQuery.parseJSON()" statements fail when I try to access the data I've formatted in the view, for my response.So my next question is how do I correctly modify the JSON response data (for each course student) returned from each request? Then once modified how do I correctly add it to a list, without breaking the JSON formatting, and causing it to not be well-formed, when I send it back to the client?This is the first time that I've attempted to do anything like this (modify and/or recombine) with JSON data, so I'm looking for an answer that my current level of Django/Python experience can't seem to provide, though I am continuing to search for answers.Any suggestions will be greatly appreciated.Thanks for the help.Henry
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com .
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users .
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/790b2c45-edc8 .-4528-9faa-4cecfc072626%40goog legroups.com
For more options, visit https://groups.google.com/d/optout .
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com .
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users .
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/ec7f326d- .1e10-40be-9e75-8363d2ffde6f% 40googlegroups.com
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/8f8cda69-8c3e-4387-8fda-6dc1929e4e7e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment