We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

Parsing JSON response

aznprncritic
aznprncritic asked
on
Medium Priority
1,078 Views
Last Modified: 2013-11-08
I have an unordered list, with each list item attributed with an id that will contain a location code.  After receiving an ajax response from the server, I am provided with an array of location codes that may or may not match the ones in my unordered list; if they do, I need to add a class of "on" to each list item.

What I need is the js needed to parse the json response and then the logic to add the css class if a location code matches one in my list.

Should be trivial for a js ninja, complicated for a novice like me!
<ul>
   <li id="a7456">Location 1</li>
   <li id="a7457">Location 2</li>
   <li id="a7458">Location 3</li> 
   <li id="a7459">Location 4</li>
</ul>
 
// and if a location code matches
<li id="a7456" class="on">Location 1</li>

Open in new window

Comment
Watch Question

Commented:
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview

Commented:
I guess as I think about it JavaScript can pretty well handle a JSON serialized string. You could replace the following:

Change:
jArray = Sys.Serialization.JavaScriptSerializer.deserialize(rValue);

To:
jArray = eval(rValue);

Commented:
Did you give up on this or figure it out? Is there something about my sample that does not make sense? Maybe I can provide things in a different context if I know that you still need help, and what is confusing you.
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview

Author

Commented:
Used my own solution

Commented:
I think you might consider assigning some points. You did ask a question. I did give a proper and working solution. Your solution does not adhere to the criteria you laid out as to working with JSON. I stayed engaged with the thread without any feedback from you except to say a week later that you solved it yourself using different techniques.

You did find another solution, but you also solicited help, wasted or not I think it's important that you acknowledge the effort that was given. If you had engaged and decided to go another route I might have a different perspective, but in this case I don't think you should assign yourself points for this.
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a free trial preview!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.