0

Can someone tell me where I am going wrong with this class. It is not evaluating the raw string back to a JSON Type in Javascript and I am not entirely sure what I am doing wrong. When I run it through JS Lint it says that it is valid JSON.

Heres the Fiddle : http://jsfiddle.net/pGygM/1/

0

2 Answers 2

3

You have a few issues...

  • jQuery isn't selected as the language in jsFiddle.
  • When using eval() to pass, wrap it in parenthesis so eval() doesn't think it's simply a block.
  • jQuery has $.parseJSON(), use that instead.
  • You have an array with a named key - that is not an array, but an object, and invalid JSON.
  • alert() won't help you debug the object as it will implicitly call toString() on the object, returning '[object Object]' which isn't too useful. Use console.log() instead.
Sign up to request clarification or add additional context in comments.

2 Comments

And a an array opener, "[", is mismatched with an object closer, "}". Looks like you missed pressing Shift in a couple places, maybe?
Here's an updated JSFiddle with alex & zostay's comment: jsfiddle.net/XcyNk
0

JSON is wrong in cameras section. Check this

http://jsbin.com/ixucil/edit#javascript,html

HTML

<input type="hidden" id="testID" value='{
  "smo": {
    "grid_columns": 3,
    "grid_rows": 3,
    "cameras": {
        "camera": {
            "camera_id": 1,
            "row": 1,
            "column": 1
        }
    }
  }
}' />​

JS

$(function(){
 var txtVal = $('#testID').val(),
 obj = $.parseJSON(txtVal);
 console.log(obj);
})

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.