jsonobject

Android: JSONObject cannot be converted to JSONArray

匿名 (未验证) 提交于 2019-12-03 01:46:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I want to get data from php file to Android using JSON. This is my code: .... HttpEntity e = r.getEntity(); String data = EntityUtils.toString(e); JSONArray timeline = new JSONArray(data); JSONObject last = timeline.getJSONObject(0); return last; When I debug the program there is JSONException on this line: JSONObject last = timeline.getJSONObject(0); Data is {"a":1,"b":2,"c":3,"d":4,"e":5} and the Exception is: org.json.JSONException: Value {"d":4,"e":5,"b":2,"c":3,"a":1} of type org.json.JSONObject cannot be converted to JSONArray 回答1: The

GSON JsonObject “Unsupported Operation Exception: null” getAsString

匿名 (未验证) 提交于 2019-12-03 01:45:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Running a Play! app with Scala. I'm doing a request where the response is expected to be a JSON string. When checking the debugger, the JsonElement returns OK with all information as expected. However, the problem is when I try to actually run methods on that JsonElement. val json = WS.url("http://maps.googleapis.com/maps/api/geocode/json?callback=?&sensor=true&address=%s", startAddress+","+startCity+","+startProvince).get.getJson val geocoder = json.getAsString The only error I get back is Unsupported Operation Exception: null and I've

Refreshing screen which uses json in android

匿名 (未验证) 提交于 2019-12-03 01:45:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a module in my application which uses json. The json gets updated always. Here i want to refresh the screen as new data arrives. Is there any method for this ? I want to refresh the screen as new data arrives or once in every 5 seconds or something(a fixed amount of time).How to do this ? I simply used a local json file to test this. I just need the code for refreshing. This is my code for json parsing : public class MainActivity extends Activity { String myjsonstring; ArrayList<Data> web = new ArrayList<Data>(); @Override protected

JSONObject (org.json) to JsonElement(com.google.gson)

匿名 (未验证) 提交于 2019-12-03 01:38:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am writing a java code in which i need to convert a JSONObject to JsonElement.Is there any way using which i can convert a JSONObject (org.json) to JsonElement(com.google.gson)? 回答1: One way that always works is to serialize the object to JSON and then parse it again: JSONObject myData = ... Gson gson = new Gson(); JsonElement element = gson.fromJson(myData.toString(), JsonElement.class); 文章来源: JSONObject (org.json) to JsonElement(com.google.gson)

Error - No instrumentation registered! Must run under a registering instrumentation

匿名 (未验证) 提交于 2019-12-03 01:34:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: A) Why when i try to run the app i get this error? My Crash Log Error Unable to start activity ComponentInfojava.lang.IllegalStateException: No instrumentation registered! Must run under a registering instrumentation. What caused that? I'm yet learning and i'll appreciate if you can explain more. This is my code import android.app.ProgressDialog; import android.os.AsyncTask; import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentPagerAdapter;

Jersey 415 Unsupported Media Type

匿名 (未验证) 提交于 2019-12-03 01:33:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have been trying since hours to correct http error 415 Unsupported Media Type but it is still showing media unsupported page. I am adding headers application/json in Postman. Here is my Java Code package lostLove; import javax.ws.rs.Consumes; import javax.ws.rs.GET; import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import org.json.JSONObject; @Path("/Story") public class Story { @POST @Consumes({"application/json"

Sending and Parsing JSON Objects [closed]

匿名 (未验证) 提交于 2019-12-03 01:29:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I would like to send messages in the form of JSON objects to a server and parse the JSON response from the server. I thought of this format for the response from the server: { "post": { "username": "someusername", "message": "this is a sweet message", "image": "http://localhost/someimage.jpg", "time": "present time" } } How much knowledge of JSON should I have to accomplish this purpose? Also it would be great if someone could provide me links of some tutorials for sending and parsing JSON Objects. 回答1: I am surprised these have not been

How to POST data in Android to server in JSON format?

匿名 (未验证) 提交于 2019-12-03 01:29:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have this JSON string. I want to POST it to the server (i.e. using the POST method). How can this be done in Android? JSON string: { "clientId": "ID:1234-1234", "device": { "userAgent": "myUA", "capabilities": { "sms": true, "data": true, "gps": true, "keyValue": { "Key2": "MyValue2", "Key1": "myvalue1" } }, "screen": { "width": 45, "height": 32 }, "keyValue": { "DevcKey2": "myValue2", "DevcKey1": "myValue1" } }, "time": 1294617435368 } How can I form this JSON array and POST it to the server? 回答1: I did it myself. JSONObject

get latitude and longitude from city name

匿名 (未验证) 提交于 2019-12-03 01:28:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: In my current android application, I would like to get the geocordinates based on an entered city name, street name or zip code. How can I accomplish this? Best Regards 回答1: get geo co-ordinates via net private static JSONObject getLocationInfo(String address) { StringBuilder stringBuilder = new StringBuilder(); try { address = address.replaceAll(" ","%20"); HttpPost httppost = new HttpPost("http://maps.google.com/maps/api/geocode/json?address=" + address + "&sensor=false"); HttpClient client = new DefaultHttpClient(); HttpResponse response;

Convert InputStream to JSONObject

匿名 (未验证) 提交于 2019-12-03 01:13:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am converting InputStream to JSONObject using following code. My question is, is there any simple way to convert InputStream to JSONObject. Without doing InputStream -> BufferedReader -> StringBuilder -> loop -> JSONObject.toString(). InputStream inputStreamObject = PositionKeeperRequestTest.class.getResourceAsStream(jsonFileName); BufferedReader streamReader = new BufferedReader(new InputStreamReader(inputStreamObject, "UTF-8")); StringBuilder responseStrBuilder = new StringBuilder(); String inputStr; while ((inputStr = streamReader