PDA

View Full Version : Cannot read JSON return from ASP.NET 3.5 WCF webservice



Roby
17 Aug 2009, 1:10 AM
I am trying to get the JSON return from ASP.NET 3.5 WCF webservice in GXT2.0 with the below code:




ModelType Jsontype = new ModelType();
Jsontype.setRoot("GetStatusListResult");
Jsontype.setRecordName("rows");
Jsontype.addField("STATUS", "STATUS");



RequestBuilder builder = new RequestBuilder(RequestBuilder.POST,
http://testservice/com.web.Service.svc/GetStatusList (http://testservice/com.web.Service.svc/GetStatusData));



HttpProxy<String> proxy = new HttpProxy<String>(builder);


JsonLoadResultReader<ListLoadResult<ModelData>> reader = new JsonLoadResultReader<ListLoadResult<ModelData>>(Jsontype);

final BaseListLoader<ListLoadResult<ModelData>> loader = new BaseListLoader<ListLoadResult<ModelData>>(
proxy, reader);

ListStore<ModelData> store = new ListStore<ModelData>(loader);
final Grid<ModelData> grid = new Grid<ModelData>(store, cm);


checked the return is a sting as:


{"GetStatusListResult":"{\"count\":7,\"rows\":[{\"STATUS\":\"Accepted\"},{\"STATUS\":\"Cancel Do Not Load\"},{\"STATUS\":\"Do Not Load\"},{\"STATUS\":\"Done Customs Review\"},{\"STATUS\":\"Rejected\"},{\"STATUS\":\"Sent\"},{\"STATUS\":\"Under Customs Review\"}]}"}


But I got such error as below:




java.lang.ClassCastException: com.google.gwt.json.client.JSONString cannot be cast to com.google.gwt.json.client.JSONArray
at com.extjs.gxt.ui.client.data.JsonReader.read(JsonReader.java:54)
at com.extjs.gxt.ui.client.data.HttpProxy$1.onResponseReceived(HttpProxy.java:76)
at com.google.gwt.http.client.Request.fireOnResponseReceivedImpl(Request.java:264)
at com.google.gwt.http.client.Request.fireOnResponseReceivedAndCatch(Request.java:236)
at com.google.gwt.http.client.Request.fireOnResponseReceived(Request.java:227)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
at com.google.gwt.dev.shell.ie.IDispatchImpl.callMethod(IDispatchImpl.java:126)
at com.google.gwt.dev.shell.ie.IDispatchProxy.invoke(IDispatchProxy.java:155)
at com.google.gwt.dev.shell.ie.IDispatchImpl.Invoke(IDispatchImpl.java:294)
at com.google.gwt.dev.shell.ie.IDispatchImpl.method6(IDispatchImpl.java:194)
at org.eclipse.swt.internal.ole.win32.COMObject.callback6(COMObject.java:117)
at org.eclipse.swt.internal.win32.OS.DispatchMessageW(Native Method)
at org.eclipse.swt.internal.win32.OS.DispatchMessage(OS.java:1925)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2966)
at com.google.gwt.dev.SwtHostedModeBase.processEvents(SwtHostedModeBase.java:235)
at com.google.gwt.dev.HostedModeBase.pumpEventLoop(HostedModeBase.java:558)
at com.google.gwt.dev.HostedModeBase.run(HostedModeBase.java:405)
at com.google.gwt.dev.HostedMode.main(HostedMode.java:232)


I am very confuse what is the problem as I am new in GXT. :-/
Anyone can help? Thanks in advance!!

Arno.Nyhm
19 Aug 2009, 2:45 AM
I am trying to get the JSON return from ASP.NET 3.5 WCF webservice in GXT2.0 with the below code:




ModelType Jsontype =

new ModelType();
Jsontype.setRoot("GetStatusListResult");
Jsontype.setRecordName("rows");
Jsontype.addField("STATUS", "STATUS");


recordName is not used by the json readers.

so i think the root is wrong.
you can also set totalname...


pls look also at this post:
http://extjs.com/forum/showthread.php?p=369894#post369894