OK.  but I need more code context.  The if statement that does the
modification is clearly python, so at that point rspnsdata must be a python
dictionary, not a JSON string.  Yet, if I understand you correctly, it is
JSON to begin with (and you are using json.loads() to turn it into python
data so that you can manipulate it, but then you must later turn it back
into a JSON string (json.dumps()) to send as a response.  So there's lots
of code you haven't shown.  If the problem were where you're concentrating,
you would have found it.  Please expand the scope of what you're showing.

On Mon, Mar 9, 2015 at 3:35 PM, Henry Versemann <fencer1...@gmail.com>
wrote:

> OK here goes. The logic in the routine which I actually doing the
> modification to each individual JSON response looks like this:
>
>         if str(objctTyp) == 'user':
>             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:
>
> The following piece of parameter data is actually what came back as my
> JSON response from the current secondary request that the application sent.
> 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
>     }
>
> }
>
> The following bit of parameter data was actually passed in as the data for
> the current student which the latest secondary request was sent for and
> whose associated data JSON data is shown above.
>
> lstobjct=
>
> {
>     'name': 'Brennan Kennedy',
>     'id':'8202'
> }
>
> The following parameter data type "user" indicates that 'name' and 'id'
> key data is passed in in the 'lstobjct' parameter and those key value pairs
> will be added to the received JSON data.
>
> 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
>>>>> <http://docs.python-requests.org/en/latest/#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
>>>>> <https://groups.google.com/d/msgid/django-users/790b2c45-edc8-4528-9faa-4cecfc072626%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>>> .
>>>>> 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
>>> <https://groups.google.com/d/msgid/django-users/ec7f326d-1e10-40be-9e75-8363d2ffde6f%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>>> 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+unsubscr...@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/4e0b9d7b-b3a9-4d8a-9c88-75ebcc9765fb%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/4e0b9d7b-b3a9-4d8a-9c88-75ebcc9765fb%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
> 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+unsubscr...@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/CAB%2BAj0u3fTHKyPJRiMxWWU2yQVOGmONw%2B_bqQXA8LgR4tVW%2B0w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to