0

I have two .json files

data_prod_ind.json

{"articles":
    [ { "title":"bla bla" } , { "title":"bla bla" } ]
}

data_prod_ind_epif.json

{"names":
    [ { "title":"bla bla" } , { "title":"bla bla" } ]
}

html

<div id="mn_1" class="mn_sb" data-articleidx="0">CONTROL RELAY</div>
...
<div id="tt_mn"></div>

<div id="content_mn"></div>

script

var idx = $(this).data('articleidx');
$.getJSON("auth/data_prod_ind.json", function(data) {
    $("#tt_mn").html($("<p class='prod_c'>" + data.articles[idx].title + "</p>"));
    $("#content_mn").html($("<p class='prod_d'>" + data.names[idx].title + "</p>"));
});

I think there would be better only one json file in which it could be:

{"articles":
    [ { "title":"bla bla" } , { "title":"ble ble" } ]
}
{"names":
    [ { "title":"blo blo" } , { "title":"blu blu" } ]
}

And I say that because it only show the content in data_prod_ind.json , not the other one.

EXAMPLE

2
  • 1
    It's not very clear from your question exactly what you are trying to achieve. Are you looking for JSON syntax that you could use to combine the same articles and names information into a single file? Commented Jan 22, 2012 at 2:26
  • i've modified append content of data_prod_ind_epif.json at the end of data_prod_ind.json and then i've modified the structure of the json function but only shows the title content from articles not from names ... :( Commented Jan 22, 2012 at 2:41

3 Answers 3

3

Well there's no reason why you can't have one file with:

{
    "articles":[{"title":"bla bla bla"},{"title":"bla bla bla"}],
    "names":[{"title":"bla bla bla"},{"title":"bla bla bla"}]
}
Sign up to request clarification or add additional context in comments.

2 Comments

additionally, to access that from jQuery callback, do this for articles' title: data.articles[idx].title
Yup, forgot to mention that ;)
1

In the getJSON you are opening one file but trying to use both of them.

You must open those separately or better have your all your data in an unique hierarchical JSON Object.

1 Comment

i'll pay attention to my sintaxis in order to make run.
-1

Valid JSON combined:

[
    {
        "articles": {
        "title": "ble ble"
        },

        "names": {
        "title": "blu blu"
        }
    }
]

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.