-
11 Apr 2012 4:21 AM #1
Problem decoding JSON string
Problem decoding JSON string
Hi,
I am facing some problem decoding JSON String.
I am sending this JSON
{\"success\":true,\"data\":[{\"key\":"+String(113556)+"}]}
but I dont know how to decode it on success function.
every time it shows error.
Can you please suggest how to decode JSON String.
thanks in advance
-
11 Apr 2012 5:32 AM #2
Code:success: function (response, opts) { var obj = Ext.decode(response.responseText); }
-
11 Apr 2012 5:38 AM #3
Hi,
I already did till that.
I wanted to get the values.
If I do console.log(obj) it still says undefined.
How to get the values out of it?
Please do let me know
thanks
-
11 Apr 2012 6:03 AM #4
also your json i don't think should have those slashes in there. maybe you are getting bad json backCode:success: function (response, opts) { var obj = Ext.decode(response.responseText); var objCount = obj.totalCount; var name = obj.items[0].name; //this is what I use cause I return items, var key= obj.data[0].key; // I think this would be what you would use }
ex. {"totalCount":1,"items":[{"number":"374432"}]}
-
11 Apr 2012 6:27 AM #5
Hi,
My JSON is being returned as
but still the code linesCode:{"success":true, "totalCount":1,"items":[{"name":1334163657}]} (I followed your suggestion)is showing error.Code:var objCount = obj.totalCount; and var name = obj.items[0].name; //this is what I use cause I return items,
It is showing errors as
Uncaught TypeError: Cannot read property 'totalCount' of undefined
&
Uncaught TypeError: Cannot read property 'items' of undefined
I am still unable to figure out the error. Searched a lot of place but no solution till now!! Please help
thanks
-
11 Apr 2012 8:52 AM #6
Use a debugger.
Stop on errors, what is obj? Is it still a string at that point? Does it need to be converted to an object?Aaron Conran
@aconran
Sencha Architect Development Team
-
11 Apr 2012 10:57 AM #7
Hi,
Yes !! debugging it.
On Place where it shows error
So after that all lines failed. I am new to this. Previously while doing extjs I used firebug but now since sencha is not compatible with chrome. I am facing trouble all the way.Code:success: function(response, result) { var responseData = Ext.decode(response.responseText);/// it says responseData is undefined screenshot attached var objCount = responseData.totalCount; var name = obj.items[0].name; Ext.Msg.alert(name)
Cannot procede until I resolve this.
So please help me
thanks
-
11 Apr 2012 11:29 AM #8
So whats the value of response.responseText?
Aaron Conran
@aconran
Sencha Architect Development Team
-
11 Apr 2012 11:31 AM #9
Nothing,
But I just figured it out
I just did this
and it showed the valueCode:var name = result.items[0].name; Ext.Msg.alert('success',name);
So, I guess it worked!!!
thanks
-
12 Apr 2012 10:25 AM #10
glad you got it working!!
but you said "sencha is not compatible with chrome." Chrome is all I use to debug senchatouch and extjs4
I suggest chrome as a debugging tool


Reply With Quote