FAQ Database Discussion Community


Get value from JSONArray

android,json,parsing,jsonobject
JSONObject obj looks like this: {"data":"Text 1","data2":"Text 2","turnCounter":0,"data3":["0","1","2"]} I have been able to retrieve data, data2, and turnCounter but I can't figure out how to get data3: Here is my attempt JSONObject obj = new JSONObject(st); if (obj.has("data")) { retVal.data = obj.getString("data"); //returns Text 1 } if (obj.has("data2")) { retVal.data2...

In Java, is there a way I could go from JSONObject to JSONStringer, or vice versa?

java,json,jsonobject
I'm a bit confused as to how I can get around what seem to be some core limitations with the JSONStringer class. I understand that JSONStringer is meant to chain together JSON rather than create it fully-formed, but in the case that a function only returns a JSONStringer, I find...

Can't parse JSON formatted response from server

javascript,json,jsonobject
I'm trying to parse a JSON formatted string like var json_response = JSON.parse(response); response is as below. It's a formatted JSON response from a Google api. { "location": { "lat": 12.9621211, "lng": 77.64804099999999 }, "accuracy": 740.0 } However I get an error saying Uncaught SyntaxError: Unexpected token { I checked...

Cannont resolve symbol JSONObject (Android Studio)

android,json,android-studio,jsonobject
I have spent two days in this. I can work with other PC, but my Android Studio doesn´t import the library, I took two captures: As yo can see in the first picture, Android Studio autocompletes my line: However: I was reading about JSONObject in Android Developers (here) and Android...

How to store all json object values in arraylist?

android,json,android-edittext,jsonobject
I have following response...from this response i am parsing bulkprice array and its objects,now what I am trying is that I need to store all the minqty values in one arraylist and want to convert all those values in Integer..but I am not able to get that.. {"status":"success","clientproduct":[{"pid":"4","name":"kangan pair","unitprice":"1500","boxqty":"1","bulkprice":[{"minqty":"10","price":"1500"},{"minqty":"15","price":"1470"},{"minqty":"20","price":"1460"}]}]} MainActivity.java...

get data from JSONObject according to a key

javascript,html,json,jsonobject
I have this JSONObject. { "headerContent": [ { "name": "User Id", "key": "userId", "type": "text", "default": "Enter User Id" }, { "name": "User Name", "key": "userName", "type": "text", "default": "Enter User Name" }, { "name": "Password", "key": "password", "type": "password", "default": "Enter Password" }, { "name": "Mobile Number", "key": "mobileNumber",...

The type or namespace name 'Json' does not exist in the namespace 'System' (are you missing an assembly reference?)

.net,json,jsonobject
I am using .NET Framework 4.5 and I'm having this issue. The type or namespace 'Json' does not exist in the namespace 'System' So, I tried to Install-Package System.Json -Version 4.0.20126.16343 but I had this issue afterwards. The type 'System.Uri' is defined in an assembly that is not referenced. You...

Using Java 8 Optional with JSONObject?

json,java-8,optional,jsonobject
GIVEN: JSONObject o = <populated from json source>; if (o.has("stuff") && response.getJSONObject("stuff").has("stuffList") && o.getJSONObject("stuff").getJSONArray("stuffList").size() > 0) { doStuff() } ASK: How can I rewrite the above using java.util.Optional so that I don't have to make all those JSONObject checks? Something like: java.util.Optional<JSONObject> _O = java.util.Optional.ofNullable(o); java.util.Optional<Integer> size = _response.map(JSONObject::getJSONObject("stuffList")...<etc>???;...

How to parse this JSON file to some ArrayList?

android,arrays,json,parsing,jsonobject
in the past i have already parsed a json file from url to local sqlite database and the json source was like the following one: [ { "origin": "accommodation", "parent": "", "en": "Accommodation" }, { "origine": "book", "parent": "shopping", "en": "Book" }, { "origin": "university", "parent": "education", "en": "University" }...

Working with JSON object Facebook Graphapi

android,json,facebook-graph-api,jsonobject
I am stuck trying to store values from a JSONObject in a arraylist. my JSONObject looks like this: {"id":"112107865788640","friends":{"summary":{"total_count":1}, "data":[{"id":"111366842530215","name":"James Amigjfihgbjd Alisonsky"}] ,"paging":{"next":""}}}, error: null} And i am trying to store the id from data and the name from data in 2 array lists fid and fname. My code: JSONArray...

Is this a valid JSONObject & if yes then how do I iterate to get all the values

parse.com,jsonobject
I have this response from server which is a valid JSON. {"Avg":[{"avg":3,"rcid":"ww44sd"},{"avg":4,"rcid":"ww24hj"},{"avg":3,"rcid":"ww36hd"},{"avg":4,"rcid":"ww89yx"},{"avg":3,"rcid":"ww64tf"},{"avg":4,"rcid":"ww76py"}]} I wrote the following code but I fail to understand how this is not a JSONObject. Logcat shows this error FATAL EXCEPTION: main java.lang.ClassCastException: java.util.HashMap cannot be cast to org.json.JSONObject ParseCloud.callFunctionInBackground("avgfunc", params, new FunctionCallback<JSONObject>() { public void...

How to use JSONObject effective in your android project

android,json,jsonobject
Recently my project has json requirement, but I've never use json before, so i want to know how to use json effective. I use Volley as my network lib, which support json default, know I can get the JSONObject or JSONArray response, and can get the data by the method...

Android Incorrect value when converting String to StringEntity

android,string,http-post,jsonobject
I am sending a string to server using HttpPost. This string is a JSONObject thath i have previously converted to String So far everything is working properly... It must be sent with content-type "application / json". To send it, convert my String to a StringEntity and add to httpPost.setEntity (my_string)...

Passing a org.json.simpleJSONArray to an Intent in Android as an Extra

java,android,json,android-intent,jsonobject
I have a problem where I receive JSONArray(from the org.json.simple.JSONArray library) from an API call and I have to pass this JSONArray to a new page/intent while trying to transfer the information in my Android App. The receive information from the API call, I get a JSONArray, which I now...

What is the difference between JSONObject accumulate and put?

json,jsonobject
I have been dabbling with JSON and I see that in the documentation (JAVA), JSONObject's put() and accumulate() pretty much do the same thing? What is that about?...

Google Map fetch dynamic LatLng index

javascript,google-maps-api-3,latitude-longitude,jsonobject
My code below trigger a simple Google Map event when the user click on the marker: google.maps.event.addListenerOnce(marker, 'click', function() { console.log(this.position); } It displays the current position of the clicked marker like this: of {j: 51.469722, C: -0.4513890000000629} In my application, I was fetching the Latitude and the Longitude of...

trying to get table row count value but got Error converting result java.lang.NullPointerException: lock == null

javascript,php,android,json,jsonobject
i'm new in this thing, so i need help with my current problem, i'm trying to get table row count value but "Error parsing data org.json.JSONException: Value Result of type java.lang.String cannot be converted to JSONObject" appear here's my rowcount.php : <?php $mysqli = new mysqli("localhost", "root", "", "smkkimmanuel2"); /*...

Getting a JSONObject from a JSONArray?

android,json,jsonobject
I'm trying get a JSONObject from a JSONArray. When I do Log.i display values of JSONArray and has JSONObject that I want. The problem is when I try get this JSONObject, throws an exception show: No value for Local or No value for TipoLocal. Local and TipoLocal are JSONObject into...

Android as a Client, Server using Spring annotation,communication in JSON format,error while receiving in server

android,spring-annotations,jsonobject
I want to develop android app which is connected to server which is developed using Spring,and they should communicate in JSON format. But When I send request to server with JSON object and try to receive it,it is showing error java.lang.UnsupportedOperationException: JsonObject at com.google.gson.JsonElement.getAsString(JsonElement.java:191) at org.magnum.dataup.VendorController.addRestaurantWebView(VendorController.java:79) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at...

How to create a dynamic JSONObject?

java,semantic-web,jsonobject
I have a little problem I've write a code that create an object from JSONObject and add some data on it like this: JSONObject outerObject = new JSONObject(); JSONArray outerArray = new JSONArray(); JSONObject innerObject1 = new JSONObject(); innerObject1.put("id", "semantic web"); innerObject1.put("url", "www.semanticweb.com"); innerObject1.put("definition", "this is the denfition of semantic...

How to compare two JSON strings when the order of entries keep changing [duplicate]

java,json,string,equals,jsonobject
This question already has an answer here: Compare two JSON objects in Java 15 answers I have a string like - {"state":1,"cmd":1} , I need to compare this with generated output but in the generated output the order keeps changing i.e. sometimes its {"state":1,"cmd":1} other times its {"cmd":1,"state":1}. Currently...

Unterminated object when converting a String to JSON

java,android,json,escaping,jsonobject
I am working with Android Studio, andI have a string variable, called sResponse (below). According to the debugger, it holds the following value: { "responseData": { "emotion":"", "lastinput":{actionResult={"value":{"label":"green","key":"1"},"result":"success","action":"displayClickableList"}, "answer":"Sorry, I did not understand.", "link": { "href":"", "target":"" }, "extraData": { }, "responseSession": { "id":"c4a5ef257851a991eb32c69132c9", "transaction":"4" }, "responseDetails": "null", "responseStatus": "200",...

Retrofit not parsing JSONObject

android,parsing,retrofit,jsonobject
A successful login returns the following JSONObject from a server: {"success":true,"message":"Sign in success.","response_data":{"user_id":"24", "email_id":"[email protected]", "secret_code": "You did it!"}} I want to put the response_data info into my User object. I used to do something like this: String getResponse = jsonObject.getString("response_data"); Gson gson = new GsonBuilder() .disableHtmlEscaping() .setFieldNamingPolicy(FieldNamingPolicy.UPPER_CAMEL_CASE) .setPrettyPrinting() .serializeNulls() .create();...

Get a String from an Array in JSON in Android Studio

java,android,arrays,json,jsonobject
I have a problem. I want to access a String ("name") from a JSONObject that has 3 arrays and I'm trying to access a particular one of those 3. This is the bigger Array. {"id":[{"id":"2","name":"Yuliem"}],"success":1,"message":"Product successfully created."} I want to access the one that's named id, and then access the...

extract string from a json object

json,extjs,textfield,jsonobject
I have an attribute in the extjs code defined as : datajson: { 'name' : 'Hello', .... } Now I need to set the value of a textfield to the name defined inside this attribute. I have tried the following but its not working: Ext.getCmp('name').setValue((this.datajson.xyz.name).toString()); The id of the textfield...

JsonObject in Java

java,json,jsonobject
Original Question: Resolved I'm producing Json from the controller using JsonObject/JsonArray: JSONObject headers = new JSONObject(); headers.put("ID", ""); headers.put("Organization Name", ""); headers.put("Submission Date", ""); headers.put("Status", ""); JSONObject organizationsHJ = new JSONObject(); organizationsHJ.put("headers", headers); array.add(organizationsHJ ); This produces JSON as: "headers":{"Status":"","Submission Date":"","Organization Name":"","ID":""} Instead I need to get the output as:...

Adding a JSON Object under another JSON Object for Android

android,arrays,json,jsonobject
I want to create a JSON Structure like this: { "request": { "slice": [ { "origin": "BLR", "destination": "CCU", "date": "2015-06-18" } ], "passengers": { "adultCount": 1, "infantInLapCount": 0, "infantInSeatCount": 0, "childCount": 0, "seniorCount": 0 }, "solutions": 20, "refundable": false } } For this I have written the following lines...

In HttpURLConnection Why don't JSONObject as Params work but String as Params are working

java,php,android,httpurlconnection,jsonobject
I am using HttpUrlConnection to post some data to my server here is the function: private String register(String myurl) throws IOException { String resp = null; try { JSONObject parameters = new JSONObject(); // parameters.put("jsonArray", ((makeJSON()))); parameters.put("key", "key");//getencryptkey()); URL url = new URL(myurl); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); // conn.setReadTimeout(10000...

JSONArray only returns 1 put?

arrays,json,jsonobject
i have a function which returns a JSON object private JSONObject retrieveData() { JSONObject json = new JSONObject(); json.put("Country", "Ireland"); json.put("Capital", "Dublin"); json.put("Country", "Spain"); json.put("Capital", "Madrid"); json.put("Country","France"); json.put("Capital", "Paris"); JSONArray ja = new JSONArray(); ja.put(json); JSONObject mainObj = new JSONObject(); mainObj.put("places", ja); return mainObj; } my output is { "places":...

Android JsonObject parsing string with double quotes

android,jsonobject
Im using JsonObject to parse a response from an API, the problem is that the resulting String have double quotes, how to get string with no quotes? JsonElement jelement = new JsonParser().parse(response); JsonObject jobject = jelement.getAsJsonObject(); String authorization = jobject.get("authorization").toString(); Log.d("mensa","parseado jwt :"+authorization); so my response looks like... parseado jwt...

Android: Rest api returns incomplete response

android,json,rest,jsonobject
i'm using a restful web service which returns data from sql server to my android app, if i get 100 records it works fine but if get 1,000 records my log shows incomplete and broken json. @Override public ArrayList<CRM_table> doInBackground(Void... params) { RestAPI api = new RestAPI(); RestAPI api =...

Use of JSONObject and JSONArray in Jmeter

arrays,json,variables,jmeter,jsonobject
I have a problem with the construction of a Json for Amazon Kinesis. This json has to have this format: { "Records": [ { "Data": "XzxkYXRhPl8x", "PartitionKey": "partitionKey1" }, { "Data": "f1PxFQo92Afh", "PartitionKey": "partitionKey2" }, { "Data": "Gi4sEdd08HypA", "PartitionKey": "partitionKey3" } ], "StreamName": "exampleStreamName" } I use an BeanShell Sampler...

How to iterate over JSON Object and get the values for each key

javascript,arrays,jsonobject
I have a JSONObject which had a JSONArray as a value for each key. { "abc" : [null, "1,3", "2,4"], "dbs" : [null, "1,4", "4,5"], "sad" : [null, "6,2", "3,4", "5,5"] } I want to iterate over the object and take the JSONArray value for each key and put it...

Map put not working Java

hashmap,put,jsonobject,linkedhashmap
I have a Map with some values, and I need to put a new entry into it, the problem is that the put "lost" the Object, and I have only the new Key into it. Here is the code public void addSeries(SerieInterface serieObject) { Map<String, Object> series = this.getSeries(); if...

Joda DateTime Json date format issue

json,datetime,gson,jodatime,jsonobject
I would like the JSON output to be in a particular date format. My JSON output is: "data":[[{"id":1,"createTimestamp":{"iMillis":1431463708237,"iChronology":{"iBase":{"iMinDaysInFirstWeek":4}}},"startTimestamp":{"iMillis":1420092000000,"iChronology":{"iBase":{"iMinDaysInFirstWeek":4}}},"endTimestamp":{"iMillis":1451541600000,"iChronology":{"iBase":{"iMinDaysInFirstWeek":4}}}}]] But I would like the timestamps to be in this format: 2015-05-12T20:48:28.237Z My code: JSONArray a = new JSONArray(); a.add(aList); JSONObject j = new...

Uncaught SyntaxError - Get the value of an object that is in another object

javascript,json,jsonobject
Can someone please explain what is wrong with my below javascript code: var testData = '{"test":"testvalue", "test2":"{"boxcolor":"bg-white", "iconcolor":"bg-aqua"}"}'; testFunction(testData); function testFunction(data) { var obj = JSON.parse(data); alert(obj.test2.boxcolor); } Here is the console error: Uncaught SyntaxError: Unexpected token b I am wanting to get the value of an object, where the...

JSONObject toString sometimes throw a ConcurrentModificationError

android,jsonobject
At the outset, sorry about not being able to provide my code. I created a JSONObject and I am converting to string and my Android app crashes sometimes with the following error. E/AndroidRuntime( 6162): java.util.ConcurrentModificationException E/AndroidRuntime( 6162): at java.util.ArrayList$ArrayListIterator.next(ArrayList.java:573) E/AndroidRuntime( 6162): at org.json.JSONArray.writeTo(JSONArray.java:612) E/AndroidRuntime( 6162): at org.json.JSONStringer.value(JSONStringer.java:233) E/AndroidRuntime( 6162): at...