5 Replies Latest reply on Oct 24, 2013 4:07 AM by Littleone7

    JSON static Text field

    oliverS Level 1

      Hello everybody,

       

       

      I want to load data from a JSON file in  two different Textfields

       

      but it does not work.

       

      I make two simple Textfields which I named

       

      "firstTXTfield" and "secondTXTfield" and put them on the stage.

       

      Now I want to load Data from a JSON file:

       

       

      [

                {

                "first" : "Hello world 01",

                },

         

      {

                "second" : "Hello world 02",

                }

      ]

       

       

      On the compositionReady I put the following code:

       

       

      $.getJSON('content.json', function(data){

       

       

                function updateInfo(i){

       

       

                                               sym.$("firstTXTfield").html(data[i].first);

                  sym.$("secondTXTfield").html(data[i].second);

       

       

                  }

       

       

                });

       

       

      Maybe someone could help

       

      THX

        • 1. Re: JSON static Text field
          resdesign Adobe Community Professional & MVP

          You need to give a value to i in order for them to show. Basically the variable needs to be initiated one way or another.

           

          i=0;

           

          sym.$("firstTXTfield").html(data[i].first);

          sym.$("secondTXTfield").html(data[i].second);

          1 person found this helpful
          • 2. Re: JSON static Text field
            Littleone7

            Hi,

             

            I have a similar query I think. i need to crab a quote from my JSON database and pass that into a symbol in edge. I've looked at a couple of posts but I'm still stuggling. My code is below:

             

            $.getJSON('http://glogis04/fm/fmService.php?getQuote&type=Operational%20Support', function(data){

             

                      function updateInfo(i){

                        i=0;

                        sym.getSymbol('righ_txt').$('Quote_txt').html(data[i].type.text);

                        }

                      });

            I also want it take a random quote for the records each time its asked.

             

            This is my first time with working with databases of any kind so real newbie here.

             

            thanks again!

            • 3. Re: JSON static Text field
              Littleone7 Level 1

              update

               

              my developer firend who created the JSON database but doesn't know edge per say edited the javascript I cave him and added a for loop too:

               

              var quotesArray = new Array();

              var currentQuote = 0;

              sym.getSymbol('righ_txt').$('Quote_txt').html("");

               

               

              $.getJSON("http://glogis04/fm/fmService.php?getQuotes&type=Technical%20Services", function(data){

                             for(var i=0; i<data.length; i++){

                                           quotesArray.push({"type":data[i].type,"text":data[i].text});

                        }

                             sym.getSymbol('righ_txt').$('Quote_txt').html(quotesArray[currentQuote].type);

              });

               

              but it still doesnt work... help

              • 4. Re: JSON static Text field
                resdesign Adobe Community Professional & MVP

                I believe you need to change this to:

                 

                 

                 

                 

                 

                $.getJSON("http://glogis04/fm/fmService.php?getQuotes&type=Technical%20Services", function(data){

                          var quotesArray = new Array();

                          var currentQuote = 0;

                          // sym.getSymbol('righ_txt').$('Quote_txt').html("");  // probably not needed.

                 

                               for(var i=0; i<data.length; i++){

                                             quotesArray.push({"type":data[i].type,"text":data[i].text});

                          }

                               sym.getSymbol('righ_txt').$('Quote_txt').html(quotesArray[currentQuot e].type);

                });

                1 person found this helpful
                • 5. Re: JSON static Text field
                  Littleone7 Level 1

                  Thanks resdesign.

                   

                  We realised it was because the two files weren't on the same server so it didn't like it. Now they are its working fine with:

                   

                  var quotesTArray = new Array();

                  var quotesOArray = new Array();

                  var quotesSArray = new Array();

                   

                   

                  $.getJSON("http://ldnpc9f1r65j/fm/fmService.php?getQuotes&type=Technical%20Services", function(data){

                                 for(var i=0; i<data.length; i++){

                                               quotesTArray.push({"type":data[i].type,"text":data[i].text});

                            }

                            });

                   

                   

                  $.getJSON("http://ldnpc9f1r65j/fm/fmService.php?getQuotes&type=Operational%20Support", function(data){

                                 for(var i=0; i<data.length; i++){

                                               quotesOArray.push({"type":data[i].type,"text":data[i].text});

                            }

                            });

                   

                   

                  $.getJSON("http://ldnpc9f1r65j/fm/fmService.php?getQuotes&type=Strategic%20and%20Financial%20Planning", function(data){

                                 for(var i=0; i<data.length; i++){

                                               quotesSArray.push({"type":data[i].type,"text":data[i].text});

                            }

                            });

                   

                   

                  // Data from JSON Database for Projects

                  var projectsTArray = new Array();

                  var projectsOArray = new Array();

                  var projectsSArray = new Array();

                   

                   

                  $.getJSON("http://ldnpc9f1r65j/fm/fmService.php?getProjects&type=Technical%20Services", function(data){

                                 for(var i=0; i<data.length; i++){

                                               projectsTArray.push({"type":data[i].type,"text":data[i].text});

                            }

                            });

                   

                   

                  $.getJSON("http://ldnpc9f1r65j/fm/fmService.php?getProjects&type=Operational%20Support", function(data){

                                 for(var i=0; i<data.length; i++){

                                               projectsOArray.push({"type":data[i].type,"text":data[i].text});

                            }

                            });

                   

                   

                  $.getJSON("http://ldnpc9f1r65j/fm/fmService.php?getProjects&type=Strategic%20and%20Financial%20Planni ng", function(data){

                                 for(var i=0; i<data.length; i++){

                                               projectsSArray.push({"type":data[i].type,"text":data[i].text});

                            }

                            });

                   

                  Then inside the click functions I ask the contents of the array I need to which saves on loading ie:

                   

                  sym.getSymbol('righ_txt').$('Quote_txt').html(quotesTArray[0].text);

                  sym.getSymbol('righ_txt').$('PE_list_txt').html(projectsTArray[0].text);

                   

                  The thing i'm now stuggling with is how to put several records from the same Array into one text box on separate lines.

                   

                  ie.

                  record 0

                  record 1

                  record 2

                  record 3

                   

                  The only way I can think to do it is to have 4 text boxes and give each of them a record to look at.

                   

                  thanks