0

I would like to use XUL and JSON like that:

<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
<window id="yourwindow" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns:html="http://www.w3.org/1999/xhtml" xmlns:h="http://www.w3.org/1999/xhtml">

<button value="click" oncommand="jsonTest()" />
<script type="text/javascript">
<![CDATA[
// put some js code here

function jsonTest(){

var funcionarios = 
    {
        "Marconildo":
        {
            "url": "http://www.google.com.br/",
            "idade": 34
        }
};

var funcionario = JSON.parse(funcionarios);

alert(funcionario.Marconildo);


}

]]>
</script>
</window>

But it do not work...what is wrong? JSON.parse? Would I import some namespace to use this function?

1 Answer 1

0

You don't need to use JSON.parse in your example because funcionarios already contains JSON object. Just alert 'funcionarios.Marconildo.url'

Here is the JSFiddle.

http://jsfiddle.net/BZ2gk/

Sign up to request clarification or add additional context in comments.

2 Comments

When i use JSON.parse? Do you have any example?
If you have a Json String and you want to convert to JSON object, then you will use JSON.parse. You can go through this post for example. stackoverflow.com/questions/8738070/…

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.