Sun
Sun

Reputation: 6888

org.json.JSONException: Value Dev of type java.lang.String cannot be converted to JSONObject

Getting String cannot be converted to JSONObject

see below code:

MainAdapter.java:-

 HashMap<String, String> resultp = new HashMap<String, String>();

// Capture ListView item click
        itemView.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                // Get the position
                resultp = data.get(position);

                Intent intent = new Intent(context, AnotherActivity.class);
                // Pass all data rank
                intent.putExtra("name", resultp.get(MainActivity.NAME));
                context.startActivity(intent);
            }
        });
        return itemView;

AnotherActivity.java:-

            String value = getIntent().getStringExtra("name");

            jsonobject =  new JSONObject(value);

Upvotes: 0

Views: 424

Answers (2)

Sun
Sun

Reputation: 6888

I got the solution, provided by @Raghunandan

     JSONObject jb;
            try {
                Intent intent = new Intent(context, AnotherActivity.class);
                jb = MainActivity.jsonarray.getJSONObject(position);
                intent.putExtra("name",jb.toString());
                context.startActivity(intent);
            } catch (JSONException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

Upvotes: 1

Vinothkumar Arputharaj
Vinothkumar Arputharaj

Reputation: 4569

 String value = getIntent().getStringExtra("name");
 jsonobject =  new JSONObject(value);

The below line should work unless value is not a valid JSONObject. Check this for valid JSON formats

Upvotes: 0

Related Questions