On Tue, Feb 28, 2012 at 9:32 PM, Rahul Rajan <[email protected]> wrote:
>
> Basically we are having trouble decoding a JSON-encoded custom python object.

JSON-encoded object as in "you're using JSONRPC"?  or JSON-encoded
object as in "we've decided to entirely roll our own service, even
before we know what's really going on"?

 :)


>
> a) We tried using python's json.loads but the browser can't find that 
> function.


import json

but why are you using json directly instead of JSONRPC?


>
> I'm guessing that is because the pyjamas compiler has trouble converting the 
> native json library to javascript?


 correct - that's why there's an implementation in javascript instead.

>
> Would it be possible to use the native json loads function somehow?
>

no but you can have an equivalent in javascript named the exact same
function, named the exact same library, doing the exact same thing.

>
> b) We looked at the dynamictable example. Does the automatic decoding happens 
> inside here?


it uses JSONService.py


>>
>> def onRemoteResponse(self, response, requestInfo):
>>
>>      people = response
>
>
> ______________________________________
>
> This is what our server sends:
>>
>> treeJSON = '[{"__jsonclass__": "Candidate.Candidate", "name": "Barack 
>> Obama"}]'
>>
>> self.mainPanel.add(HTML('pleasework2 %s' % 
>> JSONResponseTextHandler(response)))
>>
>> return treeJSON
>
>
> client's onRemoteResponse:
>>
>> from pyjamas.JSONService import JSONResponseTextHandler
>>
>> from Candidate import Candidate
>>
>> def onRemoteResponse(self, response, request_info):
>>         self.mainPanel.add(HTML('pleasework: %s' % response))
>>
>>         self.mainPanel.add(HTML('pleasework2 %s' % 
>> JSONResponseTextHandler(response)))
>
>
> What we see in the browser:
>>
>> pleasework: [{"__jsonclass__": "Candidate.Candidate", "name": "Barack 
>> Obama"}]
>>
>> pleasework2: instance of pyjamas.JSONService.JSONResponseTextHandler


>
> What we want to see: instance of Candidate.Candidate.

 ok, right: i think what you're doing is double-encoding the data.  it
looks like you're using a JSONRPC service to encode JSON data!  but
JSONRPC data *is* JSON encoded!

 please make the full source code available of what you're doing.
random code snippets is of no use.

> We would really appreciate your advice...

* start from the JSONRPC example, or one of the djangoweb examples, or
just... _anything_ but trying to write your own stuff from scratch.

* make an ABSOLUTE maximum of 5 lines of code modifications at any one time.

* DO NOT make changes that are multi-purpose.  do one change and one
change ONLY.

* make damn sure that everything - even a 1-line change - is recorded
in a git repository.

all of this advice is in the pyjamas book (somewhere).

but yes, make the full source code available and it will be possible
to tell what's going on, immediately.

l.

Reply via email to