-2

I have the following json and then converted it to a javascript object. I would like to know how I would go about getting the value from the corresponding key. I think there is an issue with the spaces between my key values.

 json = {"John Leipold":"714129198","Adrian Osika":"214102597","cioGmin":"330199393"}

This is what I have tried:

 var jsonObj = JSON.parse(response);

  for(var k in jsonObj){

    console.log('key: ' + k);
    console.log('jsonObj.k: ' + jsonObj.k);

 }

I get an 'undefined' value for the value from the key (k)

tim
  • 163
  • 1
  • 2
  • 11

1 Answers1

0

You could try the following (using bracket notation):

 console.log('jsonObj.k: ' + jsonObj[k]);

var json = "{\"John Leipold\":\"714129198\",\"Adrian Osika\":\"214102597\",\"cioGmin\":\"330199393\"}";
var jsonObj = JSON.parse(json);
for(var k in jsonObj){
    console.log('key: ' + k);
    console.log('jsonObj.k: ' + jsonObj[k]);
}
Christos
  • 53,228
  • 8
  • 76
  • 108