Cannot parse JSON data from MySQL Database

I am developing an android application that requires me to connect to a mysql database and retrieve information from it. I am using a php script to connect to the server and query it and then output the results in json format: Here is my java code that uses HttpGet to get the data and convert it to a string. It is then meant to parse the data and show it on the screen. public class HttpExample extends Activity { TextView httpStuff; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.httpex); httpStuff = (TextView) findViewById(R.id.tvHttp); GetMethodEx test = new GetMethodEx(); String returned; try { returned = test.getInternetData(); httpStuff.setText(returned); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } public class GetMethodEx { public String getInternetData() throws Exception { BufferedReader in = null; String data = ""; String returnString = null; // httpGet try { HttpClient client = new DefaultHttpClient(); URI website = new URI("http://10.0.2.2/connect.php"); HttpGet request = new HttpGet(); request.setURI(website); HttpResponse response = client.execute(request); in = new BufferedReader(new InputStreamReader(response .getEntity().getContent())); StringBuffer sb = new StringBuffer(""); String l = ""; String nl = System.getProperty("line.separator"); while ((l = in.readLine()) != null) { sb.append(l + nl); } in.close(); data = sb.toString(); // return data; } catch (Exception e) { Log.e("log_tag", "Error converting result " + e.toString()); } // parse json data try { JSONArray jArray = new JSONArray(data); for (int i = 0; i

以上就是Cannot parse JSON data from MySQL Database的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JSON 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏