Search Results

Search found 54 results on 3 pages for 'gson'.

Page 1/3 | 1 2 3  | Next Page >

  • GSON on Google App Engine throws a Security Exception

    - by Legend
    I am trying to convert an object into JSON using the GSON library on Google App Engine. For some reason, it throws this exception and I don't understand how to solve this. Any suggestions? java.lang.SecurityException: java.lang.IllegalAccessException: Reflection is not allowed on private static final int java.util.BitSet.ADDRESS_BITS_PER_WORD at com.google.appengine.runtime.Request.process-8d5b435d6736643f(Request.java) at java.lang.reflect.AccessibleObject.setAccessible(AccessibleObject.java:29) at com.google.gson.ObjectNavigator.navigateClassFields(ObjectNavigator.java:141) at com.google.gson.ObjectNavigator.accept(ObjectNavigator.java:123) at com.google.gson.JsonSerializationVisitor.getJsonElementForChild(JsonSerializationVisitor.java:148) at com.google.gson.JsonSerializationVisitor.addAsArrayElement(JsonSerializationVisitor.java:139) at com.google.gson.JsonSerializationVisitor.visitArray(JsonSerializationVisitor.java:83) at com.google.gson.ObjectNavigator.accept(ObjectNavigator.java:109) at com.google.gson.JsonSerializationVisitor.getJsonElementForChild(JsonSerializationVisitor.java:148) at com.google.gson.JsonSerializationVisitor.addAsChildOfObject(JsonSerializationVisitor.java:126) at com.google.gson.JsonSerializationVisitor.visitArrayField(JsonSerializationVisitor.java:95) at com.google.gson.ObjectNavigator.navigateClassFields(ObjectNavigator.java:154) at com.google.gson.ObjectNavigator.accept(ObjectNavigator.java:123) at com.google.gson.JsonSerializationContextDefault.serialize(JsonSerializationContextDefault.java:56) at com.google.gson.Gson.toJsonTree(Gson.java:230) at com.google.gson.Gson.toJson(Gson.java:315) at com.google.gson.Gson.toJson(Gson.java:270) at com.google.gson.Gson.toJson(Gson.java:250) at companionmodel.Sample_Model_PopulateServlet.printOutput(Sample_Model_PopulateServlet.java:59) at companionmodel.Sample_Model_PopulateServlet.doGet(Sample_Model_PopulateServlet.java:28) at javax.servlet.http.HttpServlet.service(HttpServlet.java:693) at javax.servlet.http.HttpServlet.service(HttpServlet.java:806) at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511) at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166) at com.google.apphosting.utils.servlet.ParseBlobUploadFilter.doFilter(ParseBlobUploadFilter.java:97) at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157) at com.google.apphosting.runtime.jetty.SaveSessionFilter.doFilter(SaveSessionFilter.java:35) at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157) at com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:43) at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157) at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388) at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216) at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182) at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765) at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418) at com.google.apphosting.runtime.jetty.AppVersionHandlerMap.handle(AppVersionHandlerMap.java:238) at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152) at org.mortbay.jetty.Server.handle(Server.java:326) at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542) at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:923) at com.google.apphosting.runtime.jetty.RpcRequestParser.parseAvailable(RpcRequestParser.java:76) at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404) at com.google.apphosting.runtime.jetty.JettyServletEngineAdapter.serviceRequest(JettyServletEngineAdapter.java:135) at com.google.apphosting.runtime.JavaRuntime.handleRequest(JavaRuntime.java:250) at com.google.apphosting.base.RuntimePb$EvaluationRuntime$6.handleBlockingRequest(RuntimePb.java:5838) at com.google.apphosting.base.RuntimePb$EvaluationRuntime$6.handleBlockingRequest(RuntimePb.java:5836) at com.google.net.rpc.impl.BlockingApplicationHandler.handleRequest(BlockingApplicationHandler.java:24) at com.google.net.rpc.impl.RpcUtil.runRpcInApplication(RpcUtil.java:398) at com.google.net.rpc.impl.Server$2.run(Server.java:852) at com.google.tracing.LocalTraceSpanRunnable.run(LocalTraceSpanRunnable.java:56) at com.google.tracing.LocalTraceSpanBuilder.internalContinueSpan(LocalTraceSpanBuilder.java:576) at com.google.net.rpc.impl.Server.startRpc(Server.java:807) at com.google.net.rpc.impl.Server.processRequest(Server.java:369) at com.google.net.rpc.impl.ServerConnection.messageReceived(ServerConnection.java:442) at com.google.net.rpc.impl.RpcConnection.parseMessages(RpcConnection.java:319) at com.google.net.rpc.impl.RpcConnection.dataReceived(RpcConnection.java:290) at com.google.net.async.Connection.handleReadEvent(Connection.java:474) at com.google.net.async.EventDispatcher.processNetworkEvents(EventDispatcher.java:831) at com.google.net.async.EventDispatcher.internalLoop(EventDispatcher.java:207) at com.google.net.async.EventDispatcher.loop(EventDispatcher.java:103) at com.google.net.rpc.RpcService.runUntilServerShutdown(RpcService.java:251) at com.google.apphosting.runtime.JavaRuntime$RpcRunnable.run(JavaRuntime.java:413) at java.lang.Thread.run(Unknown Source) Code I am using: Gson gson = new Gson(); String json = gson.toJson(modelObject);

    Read the article

  • Is google gson running on android?

    - by Janusz
    I'm playing arround with google gson for communication with my web back end at the moment. This and this older posts indicate that there are some problems with gson on android. I did some easy tests on the device already but maybe I just missed the bug. Edit I'm now parsing a lot more data. Generic lists etc. still not encountered the bug. Has anybody used gson on Android already? How does it work? Has somebody encountered bugs or something that will stop me from using it once it gets more complicated?

    Read the article

  • Gson module not found Blackberry Java application

    - by Curro
    Hi. I'm developing a simple application for Blackberry and i'm using Google's gson to retrieve some data from a server. The UI was working fine but when I added the gson part it started failing, it wont run. When I run the application in the simulator it show this error: "Uncaught: RuntimeException" on that annoying white screen of death and after holding the click button I can see that there is an alert dialog that says "Module 'gson-1.4' not found". However I did added "gson-1.4.jar" in the Project's Properties - Java Build Path - Add External JARs... also, the Gson objects are recognized at my code, no syntax errors at my code. BTW, I'm using Eclipse and the most recent Blackberry SDK Please help

    Read the article

  • Jackson Vs. Gson

    - by Null Pointer
    After searching through some existing libraries for JSON, I have finally ended up with these two: Jackson Google GSon I am a bit partial towards GSON, but word on the net is that GSon suffers from certain celestial performance issue. I am continuing my comparison, in the meanwhile I was looking for help to make up my mind.

    Read the article

  • Parsing Json Feeds with google Gson

    - by mnml
    I would like to know how to parse a json feed by items, eg. url / title / description for each item. I have had a look to the doc / api but, it didn't help me. This is what I got so far import com.google.gson.Gson; import com.google.gson.JsonObject; public class ImportSources extends Job { public void doJob() throws IOException { String json = stringOfUrl("http://feed.test/all.json"); JsonObject jobj = new Gson().fromJson(json, JsonObject.class); Logger.info(jobj.get("responseData").toString()); } public static String stringOfUrl(String addr) throws IOException { ByteArrayOutputStream output = new ByteArrayOutputStream(); URL url = new URL(addr); IOUtils.copy(url.openStream(), output); return output.toString(); } }

    Read the article

  • Parsing JSON with GSON

    - by Donn Felker
    I'm having some trouble with GSON, mainly deserializing from JSON to a POJO. I have the following JSON: { "events": [ { "event": { "id": 628374485, "title": "Developing for the Windows Phone" } }, { "event": { "id": 765432, "title": "Film Makers Meeting" } } ] } With the following POJO's ... public class EventSearchResult { private List<EventSearchEvent> events; public List<EventSearchEvent> getEvents() { return events; } } public class EventSearchEvent { private int id; private String title; public int getId() { return id; } public String getTitle() { return title; } } ... and I'm deserializing with the following code, where json input is the json above Gson gson = new Gson(); return gson.fromJson(jsonInput, EventSearchResult.class); However, I cannot get the list of events to populate correctly. The title and id are always null. I'm sure I'm missing something, but I'm not sure what. Any idea? Thanks

    Read the article

  • Gson Deserialize to Java Tree

    - by MountainX
    I need to deserialize some JSON to a Java tree structure that contains TreeNodes and NodeData. TreeNodes are thin wrappers around NodeData. I'll provide the JSON and the classes below. I have looked at the usual Gson help sources, including here, but I can't seem to come up with the solution. Serialization works fine with Gson. The JSON below was produced by Gson. But deserialization is the problem I need help with. Can someone show me how to write the deserializer (or suggest an alternative approach using Gson best practices)? Here is my JSON. The "data" element corresponds to class NodeData, and the "subList" JSON element corresponds to Java class TreeNode. { "data": { "version": "032", "name": "root", "path": "/", "id": "1", "parentId": "0", "toolTipText": "rootNode" }, "subList": [ { "data": { "version": "032", "name": "level1", "labelText": "Some Label Text at Level1", "path": "/root", "id": "2", "parentId": "1", "toolTipText": "a tool tip for level1" }, "subList": [ { "data": { "version": "032", "name": "level1_1", "labelText": "Label level1_1", "path": "/root/level1", "id": "3", "parentId": "2", "toolTipText": "ToolTipText for level1_1" } }, { "data": { "version": "032", "name": "level1_2", "labelText": "Label level1_2", "path": "/root/level1", "id": "4", "parentId": "2", "toolTipText": "ToolTipText for level1_2" } } ] }, { "data": { "version": "032", "name": "level2", "path": "/root", "id": "5", "parentId": "1", "toolTipText": "ToolTipText for level2" }, "subList": [ { "data": { "version": "032", "name": "level2_1", "labelText": "Label level2_1", "path": "/root/level2", "id": "6", "parentId": "5", "toolTipText": "ToolTipText for level2_1" }, "subList": [ { "data": { "version": "032", "name": "level2_1_1", "labelText": "Label level2_1_1", "path": "/root/level2/level2_1", "id": "7", "parentId": "6", "toolTipText": "ToolTipText for level2_1_1" } } ] } ] } ] } Here are the Java classes: public class Tree { private TreeNode rootElement; private HashMap<String, TreeNode> indexById; private HashMap<String, TreeNode> indexByKey; private long nextAvailableID = 0; public Tree() { indexById = new HashMap<String, TreeNode>(); indexByKey = new HashMap<String, TreeNode>(); } public long getNextAvailableID() { return this.nextAvailableID; } ... [snip] ... } public class TreeNode { private Tree tree; private NodeData data; public List<TreeNode> subList; private HashMap<String, TreeNode> indexById; private HashMap<String, TreeNode> indexByKey; //this default ctor is used only for Gson deserialization public TreeNode() { this.tree = new Tree(); indexById = tree.getIdIndex(); indexByKey = tree.getKeyIndex(); this.makeRoot(); tree.setRootElement(this); } //makes this node the root node. Calling this obviously has side effects. public NodeData makeRoot() { NodeData rootProp = new NodeData(TreeFactory.version, "example", "rootNode"); String nextAvailableID = getNextAvailableID(); if (!nextAvailableID.equals("1")) { throw new IllegalStateException(); } rootProp.setId(nextAvailableID); rootProp.setParentId("0"); rootProp.setKeyPathOnly("/"); rootProp.setSchema(tree); this.data = rootProp; rootProp.setNode(this); indexById.put(rootProp.getId(), this); indexByKey.put(rootProp.getKeyFullName(), this); return rootProp; } ... [snip] ... } public class NodeData { protected static Tree tree; private LinkedHashMap<String, String> keyValMap; protected String version; protected String name; protected String labelText; protected String path; protected String id; protected String parentId; protected TreeNode node; protected String toolTipText;//tool tip or help string protected String imagePath;//for things like images; not persisted to properties protected static final String delimiter = "/"; //this default ctor is used only for Gson deserialization public NodeData() { this("NOT_SET", "NOT_SET", "NOT_SET"); } ... [snip] ... } Side note: The tree data structure is a bit strange, as it includes indexes. Obviously, this isn't a typical search tree. In fact, the tree is used mainly to create a hierarchical path element (String) in each NodeData element. (Example: "path": "/root/level2/level2_1".) The indexes are actually used for NodeData retrieval.

    Read the article

  • Java + GWT + GSON on server side

    - by Jan
    Hi everybody. I already read that there is no possibility to run GSON in GWT client code, but that it is possible to run it in server code. The latter one is which I'm trying to achive, but not getting to work. I thought any class within the com.whatever.server package has access to the whole JRE namespace including reflection. It seems that that is not the point. So how managed all those developers to use GSON in GWT server code? (I'm new to GWT, so the answer may be really easy.) Thanks.

    Read the article

  • How deserealizing JSON with GSON

    - by loko
    I have one result of APPI http://developer.yahoo.com/geo/placefinder/guide/examples.html, I need to deserealizing the result JSON of example only with GSON http://where.yahooapis.com/geocode?location=San+Francisco,+CA&flags=J&appid=yourappid But i dont now have to do the class for deserealizing one JSON with array This is the reponse: {"ResultSet": {"version":"1.0", "Error":0, "ErrorMessage":"No error", "Locale":"en_US", "Quality":40, "Found":1, "Results":[ {"quality":40, "latitude":"37.779160", "longitude":"-122.420049", "offsetlat":"37.779160", "offsetlon":"-122.420049", "radius":5000, "name":"", "line1":"", "line2":"San Francisco, CA", "line3":"", "line4":"United States", "house":"", "street":"", "xstreet":"", "unittype":"", "unit":"", "postal":"", "neighborhood":"", "city":"San Francisco", "county":"San Francisco County", "state":"California", "country":"United States", "countrycode":"US", "statecode":"CA", "countycode":"", "uzip":"94102", "hash":"C1D313AD706E3B3C", "woeid":12587707, "woetype":9}] } } Im trying to deserealizing of this way but i couldn´t do that, please help me to do the correct class to get the JSON with GSON. public class LocationAddress { private ResultSet resultset; public static class ResultSet{ private String version; private String Error; private String ErrorMessage; private List<Results> results; } public static class Results{ private String quality; private String latitude; private String longitude; public String getQuality() { return quality; } public void setQuality(String quality) { this.quality = quality; } public String getLatitude() { return latitude; } public void setLatitude(String latitude) { this.latitude = latitude; } public String getLongitude() { return longitude; } public void setLongitude(String longitude) { this.longitude = longitude; } } }

    Read the article

  • Convert JSON to HashMap using Gson in Java

    - by mridang
    Hi, I'm requesting data from a server which returns data in the JSON format. Casting a HashMap into JSON when making the request wasn't hard at all but the other way seems to be a little tricky. The JSON response looks like this: { "header" : { "alerts" : [ { "AlertID" : "2", "TSExpires" : null, "Target" : "1", "Text" : "woot", "Type" : "1" }, { "AlertID" : "3", "TSExpires" : null, "Target" : "1", "Text" : "woot", "Type" : "1" } ], "session" : "0bc8d0835f93ac3ebbf11560b2c5be9a" }, "result" : "4be26bc400d3c" } What way would be easiest to access this data? I'm using the GSON module. Cheers.

    Read the article

  • Java: Using GSon incorrectly? (null pointer exception)

    - by Rosarch
    I'm trying to get the hits of a google search from a string of the query. public class Utils { public static int googleHits(String query) throws IOException { String googleAjax = "http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q="; String json = stringOfUrl(googleAjax + query); JsonObject hits = new Gson().fromJson(json, JsonObject.class); return hits.get("estimatedResultCount").getAsInt(); } public static String stringOfUrl(String addr) throws IOException { ByteArrayOutputStream output = new ByteArrayOutputStream(); URL url = new URL(addr); IOUtils.copy(url.openStream(), output); return output.toString(); } public static void main(String[] args) throws URISyntaxException, IOException { System.out.println(googleHits("odp")); } } The following exception is thrown: Exception in thread "main" java.lang.NullPointerException at odp.compling.Utils.googleHits(Utils.java:48) at odp.compling.Utils.main(Utils.java:59) What am I doing incorrectly? Should I be defining an entire object for the Json return? That seems excessive, given that all I want to do is get one value. For reference: the returned JSON structure.

    Read the article

  • How do I use Google's Gson API to deserialize JSON properly?

    - by FK82
    Hi, In short, this is a sketch of the JSON object I want to parse in JAVA: { object1: { item1: //[String | Array | Object] , item2: // ... //<> more items object2: { // } //<> more objects } These are the POJO s I created for parsing (I'll leave out the import statements for brevity's sake): (1) The representation of the complete JSON object public class JObjectContainer { private List<JObject> jObjects ; public JObjectContainer() { // } //get & set methods } (2) The representation of the nested objects: public class JObject { private String id ; private List<JNode> jObjects ; public JObject() { // } //get & set methods } (3) The representation of the items: public class JNode { private JsonElement item1 ; private JsonElement item2 ; //<> more item fields public JNode() { // } //get & set methods } Now, creating a Gson instance (FileReader for importing the jsonFile), Gson gson = new Gson() ; JObjectContainer joc = gson(jsonFile,JObjectContainer.class) ; I get a NullPointerException whenever I try to access the parseable object (e.g. through a ListIterator). Gson does however create an object of the class I specified and does not throw any subsequent errors. I know that this has been done before. So, what am I missing? TIA

    Read the article

  • Gson serialization depending on field value

    - by Serj Lotutovici
    I have a POJO that is similar to: public class MyGsonPojo { @Expose @SerializedName("value1") private String valueOne; @Expose @SerializedName("value2") private boolean valueTwo; @Expose @SerializedName("value3") private int valueThree; // Getters and other stuff here } The issue is that this object has to be serialized into a json body for a call to the server. Some fields are optional for the request and if I even send it with default and null values, the API responds differently (Unfortunately changing the api is not an option). So basically I need to exclude fields from serialization if any of them is set to a default value. For example if the field valueOne is null the resulting json should be: { "value2" : true, "value3" : 2 } Any idea how to make this a painless effort? I wouldn't want to build the json body manually. Any help would be great. Thank you in advice.

    Read the article

  • Reflection Permission problems when using the GSON library in a applet.

    - by mridang
    I'm writing an Applet that makes some JSON-RPC calls. I'm using the Google JSON library (GSON) to cast the response JSON into a class. Thsi seems to work fine as is but when I use this code in my Applet, I'm hit with a java.lang.reflect.reflectpermission. From what I read on this thread on SO, it seems that since GSON uses Reflection, I cannot use it in Applets unless I explicitly modify the security policy. How can I get around this? I've created a bunch of classes in my application and was using the Gson.fromJson method to cast it into the class. Is there any way to achieve the same functionality without having to re-write half my code. (The complexity of dealing with JSON in Java seems to be in a league of its own!) Thanks in advance guys.

    Read the article

  • Should GSON ignore varying types if they're not used in a class?

    - by loeschg
    I'm making an API call that returns JSON which has a particular field which either returns false or a map depending on content. It's a field that I don't care about. I expected GSON to ignore this particular field, though it doesn't seem to be. The object generation fails with the following message: com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected a string but was BEGIN_OBJECT at line 1 column 403560 I've seen this particular question (Gson deserialize json with varying value types). I want to make sure I need to make a custom deserializer before doing so. I'm wondering if I may have another issue. edit: Example: "anonymous_flag": { } vs "anonymous_flag": "yes" Another Edit: I actually had the field in my model object... I was referencing the wrong class. Judge away :)

    Read the article

  • How do I add a library in Eclipse?

    - by jul
    hi, I downloaded the Gson library from http://code.google.com/p/google-gson/. The archive contains the following jar files: google-gson-1.3/gson-1.3-javadoc.jar google-gson-1.3/gson-1.3.jar google-gson-1.3/gson-1.3-sources.jar How do I set my Eclipse to be able to use the package in my projects? Where do I put the documentation? Thanks jul

    Read the article

  • Is there a JSON library that can serialize Proxy objects?

    - by gmoore
    Using ActiveObjects as my ORM and Gson as my JSON processor. Ran into a problem going toJson from persisted objects. The problem is that my persisted class is actually an Interface and AO is proxying that object under the hood. Here's some sample code: Venue venue = manager.get(Venue.class, id); gson.toJson(venue); Comes up with this exception: java.lang.UnsupportedOperationException: Expecting parameterized type, got interface java.lang.reflect.InvocationHandler. Are you missing the use of TypeToken idiom? See http://sites.google.com/site/gson/gson-user-guide#TOC-Serializing-and... Because venue.getClass().getName() gives: $Proxy228 I've tried a few solutions in various combinations: gsonBuilder.registerTypeAdapter(Venue.class, newVenueSerializer()); Type listType = new TypeToken<Venue>() {}.getType(); Nothing has worked so far and I'm using a wonky field-by-field workaround. Any suggestions? I'm not married to Gson, so if there's an alternative library that can do this I'd be happy to use it.

    Read the article

  • Serializing JSON string to object

    - by user1476075
    I am trying to parse through a JSON string and convert it to the following POJO: package apicall; //POJO representation of OAuthAccessToken public class OAuthAccessToken { private String tokenType; private String tokenValue; public OAuthAccessToken(String tokenType,String tokenValue) { this.tokenType=tokenType; this.tokenValue=tokenValue; } public String toString() { return "tokenType="+tokenType+"\ntokenValue="+tokenValue; } public String getTokenValue() { return tokenValue; } public String getTokenType() { return tokenType; } } In order to do this I have written the following code: Gson gson=new Gson(); String responseJSONString="{\"access_token\" : \"2YotnFZFEjr1zCsicMWpAA\",\"token_type\" : \"bearer\"}"; OAuthAccessToken token=gson.fromJson(responseJSONString, OAuthAccessToken.class); System.out.println(token); When I run the code, I get the following output: tokenType=null tokenValue=null Instead of tokenType=bearer tokenValue=2YotnFZFEjr1zCsicMWpAA I dont understand if there's anything I've done wrong. Please help.

    Read the article

  • Fetching JSON object from Servlet Java

    - by ChrisA
    I want to create an application that will fetch a JSON object from a servlet to deserialize it, and then use its variables to do other things. My servlet has the following code in the doPost: protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { ObjectOutputStream os; os = new ObjectOutputStream(response.getOutputStream()); String s = new String("A String"); Gson gson = new Gson(); String gsonObject= gson.toJson(s); os.writeObject(gsonObject); os.close(); } Now, while the servlet is running, I can access it via a browser, if I post same code in the doGet method, that would download a servlet file, which is not what I want. What should I use in my second application that would connect to the servlet, fetch the object, so that I can manipulate it later? Thanks in advance.

    Read the article

  • Is the escaping provided by the Google-Gson library enough to ensure a safe JSON payload?

    - by Lifetime_Learner
    I am currently using the Google-Gson library to convert Java objects into JSON inside a web service. Once the object has been converted to JSON, it is returned to the client to be converted into a JSON object using the JavaScript eval() function. Is the character escaping provided by the Gson library enough to ensure that nothing nasty will happen when I run the eval() function on the JSON payload? Do I need to HTML Encode the Strings in the Java Objects before passing them to the Gson library? Are there any other security concerns that I should be aware of?

    Read the article

  • Code in FOR loop not executed

    - by androniennn
    I have a ProgressDialog that retrieves in background data from database by executing php script. I'm using gson Google library. php script is working well when executed from browser: {"surveys":[{"id_survey":"1","question_survey":"Are you happy with the actual government?","answer_yes":"50","answer_no":"20"}],"success":1} However, ProgressDialog background treatment is not working well: @Override protected Void doInBackground(Void... params) { String url = "http://192.168.1.4/tn_surveys/get_all_surveys.php"; HttpGet getRequest = new HttpGet(url); Log.d("GETREQUEST",getRequest.toString()); try { DefaultHttpClient httpClient = new DefaultHttpClient(); Log.d("URL1",url); HttpResponse getResponse = httpClient.execute(getRequest); Log.d("GETRESPONSE",getResponse.toString()); final int statusCode = getResponse.getStatusLine().getStatusCode(); Log.d("STATUSCODE",Integer.toString(statusCode)); Log.d("HTTPSTATUSOK",Integer.toString(HttpStatus.SC_OK)); if (statusCode != HttpStatus.SC_OK) { Log.w(getClass().getSimpleName(), "Error " + statusCode + " for URL " + url); return null; } HttpEntity getResponseEntity = getResponse.getEntity(); Log.d("RESPONSEENTITY",getResponseEntity.toString()); InputStream httpResponseStream = getResponseEntity.getContent(); Log.d("HTTPRESPONSESTREAM",httpResponseStream.toString()); Reader inputStreamReader = new InputStreamReader(httpResponseStream); Gson gson = new Gson(); this.response = gson.fromJson(inputStreamReader, Response.class); } catch (IOException e) { getRequest.abort(); Log.w(getClass().getSimpleName(), "Error for URL " + url, e); } return null; } @Override protected void onPostExecute(Void result) { super.onPostExecute(result); Log.d("HELLO","HELLO"); StringBuilder builder = new StringBuilder(); Log.d("STRINGBUILDER","STRINGBUILDER"); for (Survey survey : this.response.data) { String x= survey.getQuestion_survey(); Log.d("QUESTION",x); builder.append(String.format("<br>ID Survey: <b>%s</b><br> <br>Question: <b>%s</b><br> <br>Answer YES: <b>%s</b><br> <br>Answer NO: <b>%s</b><br><br><br>", survey.getId_survey(), survey.getQuestion_survey(),survey.getAnswer_yes(),survey.getAnswer_no())); } Log.d("OUT FOR","OUT"); capitalTextView.setText(Html.fromHtml(builder.toString())); progressDialog.cancel(); } HELLO Log is displayed. STRINGBUILDER Log is displayed. QUESTION Log is NOT displayed. OUT FOR Log is displayed. Survey Class: public class Survey { int id_survey; String question_survey; int answer_yes; int answer_no; public Survey() { this.id_survey = 0; this.question_survey = ""; this.answer_yes=0; this.answer_no=0; } public int getId_survey() { return id_survey; } public String getQuestion_survey() { return question_survey; } public int getAnswer_yes() { return answer_yes; } public int getAnswer_no() { return answer_no; } } Response Class: public class Response { ArrayList<Survey> data; public Response() { data = new ArrayList<Survey>(); } } Any help please concerning WHY the FOR loop is not executed. Thank you for helping.

    Read the article

  • JSON array deserialization is crashing the Dalvik VM

    - by Sam
    I have some code grabbing a JSON array from my server and initially storing it as a string. This all works fine until I try and deserialize it using google's gson fromJson method. LogCat spits out the error: 04-08 17:46:35.163: ERROR/dalvikvm(401): Can't shrink stack: curFrame is in reserved area (0x41049000 0x410491c4) My code that causes the error is: String[] results = gson.fromJson(returnString, String[].class); Can anyone shed some light on what I am doing wrong? Cheers, Sam

    Read the article

  • Return type value if RunTimeException has been thrown and not catched.

    - by Alfred
    I am using Gson to parse Json. What I don't understand what the return type will be if you don't catch the Runtime Exception. I was expecting it to be null, but it is not null when evaluating with a simple if statement. My code looks something like this: public X x() { return gson.fromJson(jsonString, X.class); } then from another function I call the function: public void y() { final X x = x(); if (x == null) { System.out.println("x == null") } } I was expecting x to be null, but it isn't because the print statement is not called? What is the value of x? How can if them. I have my problem by using a catch block in the x() function and returning null. But I am just wondering what the value of function x() is(if any?)? Hopefully I make any sense at all.

    Read the article

1 2 3  | Next Page >