F
F
Fotonick2015-07-16 22:43:11
Java
Fotonick, 2015-07-16 22:43:11

How to get key from JSON for specific value?

There is JSON with car brands. I put the list of brands in the drop-down list by parsing JSON into an ArrayList. The brand selected by the user gets into string. How can I now find a key in JSON whose value will be equal to this very string, that is, the selected car brand? After this key will be sent to get a list of models for this brand.
Here is my click handler in the list of brands, but I don’t know what to write in a loop with an iterator.

markaSp.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {



                selectMarka = markaSp.getSelectedItem().toString();



                for (Iterator<String> iter = jsonResponseMarki.keys(); iter.hasNext(); ) {
                    String key = iter.next();


                }

                new SendMarkaGetModel().execute();
                TextView vibor = (TextView) findViewById(R.id.vibor);
                vibor.setText(selectMarka);


            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {

            }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
one pavel, 2015-07-17
@onepavel

If you only insert strings when parsing Json into an arrayList, then use object-oriented programming

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question