Estoy tratando de leer este Json que contiene arreglos, pero me da el siguiente error, lo estoy leyendo con JSONArray, intenté recorrerlo con un for
pero no me deja extraer los objetos dentro del json. ¿alguien sabe que puedo hacer o que estoy haciendo mal?
12-05 09:56:59.051 16157-16157/pubeat.app.version1_0 W/System.err: org.json.JSONException: Value {"Cerca de ti":{"nombre":"Cerca de ti","promos":[{"prom_id":"21","neg_id":"3","prom_desc":"prmo especial","logo":"https:\/\/pubeat.com.mx\/pubeat\/system\/ajax\/Logo.php?prom_id=21","neg_nombre":"Alitas Wings Consti","vip":"0","calificacion":"4","distancia":"0"},{"prom_id":"9","neg_id":"3","prom_desc":"chelas 2x1 todos los viernes","logo":"https:\/\/pubeat.com.mx\/pubeat\/system\/ajax\/Logo.php?prom_id=9","neg_nombre":"Alitas Wings Consti","vip":"0","calificacion":"4","distancia":"0"},{"prom_id":"18","neg_id":"12","prom_desc":"promo para ffff","logo":"https:\/\/pubeat.com.mx\/pubeat\/system\/ajax\/Logo.php?prom_id=18","neg_nombre":"fffffff","vip":"0","calificacion":null,"distancia":"0"}]},"Recomendadas":{"nombre":"Recomendadas","promos":[]},"Mas Populares":{"nombre":"Mas Populares","promos":[{"prom_id":"15","neg_id":"9","prom_desc":"promociones por hora","logo":"https:\/\/pubeat.com.mx\/pubeat\/system\/ajax\/Logo.php?prom_id=15","neg_nombre":"Wings Tesistan","vip":"0","calificacion":"5","distancia":null},{"prom_id":"21","neg_id":"3","prom_desc":"prmo especial","logo":"https:\/\/pubeat.com.mx\/pubeat\/system\/ajax\/Logo.php?prom_id=21","neg_nombre":"Alitas Wings Consti","vip":"0","calificacion":"4","distancia":"0"},{"prom_id":"9","neg_id":"3","prom_desc":"chelas 2x1 todos los viernes","logo":"https:\/\/pubeat.com.mx\/pubeat\/system\/ajax\/Logo.php?prom_id=9","neg_nombre":"Alitas Wings Consti","vip":"0","calificacion":"4","distancia":"0"}]},"Promos Decembrinas":{"nombre":"Promos Decembrinas","promos":[{"prom_id":"22","neg_id":"9","prom_desc":"programa tus posadas para este año","logo":"https:\/\/pubeat.com.mx\/pubeat\/system\/ajax\/Logo.php?prom_id=22","neg_nombre":"Wings Tesistan","vip":"0","calificacion":"5","distancia":null},{"prom_id":"22","neg_id":"9","prom_desc":"programa tus posadas para este año","logo":"https:\/\/pubeat.com.mx\/pubeat\/system\/ajax\/Logo.php?prom_id=22","neg_nombre":"Wings Tesistan","vip":"0","calificacion":null,"distancia":null}]},"Promociones Hallowen":{"nombre":"Promociones Hallowen","promos":[{"prom_id":"20","neg_id":"9","prom_desc":"promo de hallowen","logo":"https:\/\/pubeat.com.mx\/pubeat\/system\/ajax\/Logo.php?prom_id=20","neg_nombre":"Wings Tesistan","vip":"0","calificacion":null,"distancia":null},{"prom_id":"20","neg_id":"66","prom_desc":"promo de hallowen","logo":"https:\/\/pubeat.com.mx\/pubeat\/system\/ajax\/Logo.php?prom_id=20","neg_nombre":"minegocio58","vip":"0","calificacion":null,"distancia":"0"},{"prom_id":"20","neg_id":"101","prom_desc":"promo de hallowen","logo":"https:\/\/pubeat.com.mx\/pubeat\/system\/ajax\/Logo.php?prom_id=20","neg_nombre":"minegocio93","vip":"0","calificacion":null,"distancia":"0"},{"prom_id":"20","neg_id":"10","prom_desc":"promo de hallowen","logo":"https:\/\/pubeat.com.mx\/pubeat\/system\/ajax\/Logo.php?prom_id=20","neg_nombre":"Wings Army ","vip":"0","calificacion":"5","distancia":"0"},{"prom_id":"20","neg_id":"46","prom_desc":"promo de hallowen","logo":"https:\/\/pubeat.com.mx\/pubeat\/system\/ajax\/Logo.php?prom_id=20","neg_nombre":"minegocio38","vip":"0","calificacion":null,"distancia":"0"},{"prom_id":"20","neg_id":"81","prom_desc":"promo de hallowen","logo":"https:\/\/pubeat.com.mx\/pubeat\/system\/ajax\/Logo.php?prom_id=20","neg_nombre":"minegocio73","vip":"0","calificacion":null,"distancia":"0"},{"prom_id":"20","neg_id":"26","prom_desc":"promo de hallowen","logo":"https:\/\/pubeat.com.mx\/pubeat\/system\/ajax\/Logo.php?prom_id=20","neg_nombre":"minegocio18","vip":"0","calificacion":null,"distancia":"0"},{"prom_id":"20","neg_id":"61","prom_desc":"promo de hallowen","logo":"https:\/\/pubeat.com.mx\/pubeat\/system\/ajax\/Logo.php?prom_id=20","neg_nombre":"minegocio53","vip":"0","calificacion":null,"distancia":"0"},{"prom_id":"20","neg_id":"96","prom_desc":"promo de hallowen","logo":"https:\/\/pubeat.com.mx\/pubeat\/system\/ajax\/Logo.php?prom_id=20","neg_nombre":"minegocio88","vip":"0","calificacion":null,"distancia":"0"},{"prom_id":"20","neg_id":"131","prom_desc":"promo de hallowen","
12-05 09:56:59.051 16157-16157/pubeat.app.version1_0 W/System.err: at org.json.JSON.typeMismatch(JSON.java:111)
12-05 09:56:59.051 16157-16157/pubeat.app.version1_0 W/System.err: at org.json.JSONArray.<init>(JSONArray.java:96)
12-05 09:56:59.051 16157-16157/pubeat.app.version1_0 W/System.err: at org.json.JSONArray.<init>(JSONArray.java:108)
12-05 09:56:59.051 16157-16157/pubeat.app.version1_0 W/System.err: at pubeat.app.version1_0.PromosCardViewFragment$1.onResponse(PromosCardViewFragment.java:59)
12-05 09:56:59.051 16157-16157/pubeat.app.version1_0 W/System.err: at pubeat.app.version1_0.PromosCardViewFragment$1.onResponse(PromosCardViewFragment.java:52)
El código es:
public class PromosCardViewFragment extends Fragment {
ArrayList<FuentePromosInfo> listaFuenteInfo;
String imgUrl = "http://www.teorema.com.mx/wp-content/uploads/agua-vital.jpg";
String imfUrl2 = "http://arribaelcampo.com.mx/wp-content/uploads/2017/03/agua-1.jpg";
public PromosCardViewFragment() {
// Required empty public constructor
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
//Creamos las variables en donde se guardará el url de la imagen obtenida del json
//Creamos arreglo para poblar CardViews de promos con las imagenes
listaFuenteInfo = new ArrayList<FuentePromosInfo>();
Response.Listener<String> promosListener = new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
JSONArray promJson = new JSONArray(response);
Toast.makeText(getContext(), (CharSequence) promJson, Toast.LENGTH_SHORT).show();
} catch (JSONException e) {
e.printStackTrace();
}
}
};
RecyclerView contenedor = (RecyclerView) view.findViewById(R.id.recyclerContenedor);
contenedor.setHasFixedSize(true);
LinearLayoutManager layout = new LinearLayoutManager(getContext());
layout.setOrientation(LinearLayoutManager.VERTICAL);
contenedor.setAdapter(new PromosCardViewAdapter(listaFuenteInfo));
contenedor.setLayoutManager(layout);
PromosInfoRequest promosInfoRequest = new PromosInfoRequest(promosListener);
RequestQueue queue = Volley.newRequestQueue(getContext());
queue.add(promosInfoRequest);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_promos_card_view, container, false);
}
}