Link to home
Start Free TrialLog in
Avatar of alisal
alisal

asked on

How to store Key, Value and use them later

I am receiving the following in a json file:

ownerProperty: User=0101|Name=kjhadf|kahdf=1|RefId=876234878234hg

Open in new window


I need to read, split and store the key and value, create a dropdown using the value. Then upon user choice (on dropdown), I need to update the json using the key.

Any hint would be apreciated.
Avatar of alisal
alisal

ASKER

Addition information:

I found a solution online:

var str = "|User=0101|Name=ImNewUser|IsAdmin=0|RefId=23ae2123cd223bf235|";

var result = {};
str.split('|').forEach(function(x){
    var arr = x.split('=');
    arr[1] && (result[arr[0]] = arr[1]);
});

Open in new window


it does work, but how do I access to each key and value?
"result" is an object which will contain fields whose names are those to the left of the equals sign and whose values are those to the right.

Knowing the field one can simply write "result.User", "result.IsAdmin" and so on.
Not knowing the fields you can enumerate them with a for loop.  for(var key in obj) {.....}

Lots of details on Javascript objects here http://javascriptissexy.com/javascript-objects-in-detail/
inter alia - because there are literally thousands of web sites expounding the beauty of Javascript objects.
Avatar of alisal

ASKER

I've requested that this question be deleted for the following reason:

Answers are all google search result, too general
You asked a question and got an answer. If it is not good enough or you need additional help, just ask. deletion is not on.
ASKER CERTIFIED SOLUTION
Avatar of Scott Fell
Scott Fell
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of alisal

ASKER

Thank you