i have to get json data from a website, by giving my device id . i am using jsonrequest for that but its not working,
class MainActivity : AppCompatActivity() {
lateinit var textView: TextView
lateinit var button: Button
var jsonObject = JSONObject()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
textView = findViewById(R.id.txtData)
button=findViewById(R.id.btnparse)
if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.INTERNET) != PackageManager.PERMISSION_GRANTED ) {
ActivityCompat.requestPermissions(this, arrayOf(android.Manifest.permission.INTERNET), 999)
}
}
fun jsonParse(view: View) {
val requestQueue = Volley.newRequestQueue(this)
val url = "http://-----/OrderingSystem.svc/GetData?devid={device_id}&table={login or customer_info}"
val requestJson = JsonObjectRequest(Request.Method.GET, url, null, { jsonResult ->
try {
val x = jsonResult.getJSONObject("devid")
Toast.makeText(applicationContext, " success ", Toast.LENGTH_SHORT).show()
} catch (e: Exception) {
Toast.makeText(applicationContext, "catch error", Toast.LENGTH_SHORT).show()
}
},
{ jsonError ->
jsonError.printStackTrace()
Toast.makeText(applicationContext, jsonError.toString(), Toast.LENGTH_SHORT).show()
})
requestQueue.add(requestJson)
}
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
if (requestCode == 999 && grantResults.isNotEmpty()) {
Toast.makeText(applicationContext, "Permission Granted", Toast.LENGTH_SHORT).show()
}
}
}
question from:
https://stackoverflow.com/questions/65934839/i-am-using-jsonrequest-for-that-but-its-not-working 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…