JSON ERROR

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
jwtea
Posts: 66
Joined: Fri Mar 23, 2018 2:01 am

JSON ERROR

Post by jwtea » Fri Apr 27, 2018 8:20 am

Hello, can i know what the issue over here and the solution? can't seem to make this work.
I'm using easy json and the bold and underline sentence is the error.


on mouseup
create group "mainbox"

put 0 into myLoop
put 242 into myPosition1
put 1 into myID
put 0 into testname

repeat until myLoop = 5

add 1 to myLoop
add 50 to myPosition1
add 1 to myID
add 10 to testname
create field ""&testname&"" in group "mainbox"
move it to 158,myPosition1

put tArray["users"][myID]["idnumber"] into field ""&testname&""

end repeat
end mouseup

bangkok
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 937
Joined: Fri Aug 15, 2008 7:15 am

Re: JSON ERROR

Post by bangkok » Fri Apr 27, 2018 11:13 am

jwtea wrote:
Fri Apr 27, 2018 8:20 am

put tArray["users"][myID]["idnumber"] into field ""&testname&""
It's obvious : why do you put a double quotes before and after testname ?

Code: Select all

put tArray["users"][myID]["idnumber"] into field testname

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: JSON ERROR

Post by bogs » Fri Apr 27, 2018 3:01 pm

bangkok wrote:
Fri Apr 27, 2018 11:13 am
why do you put a double quotes before and after testname ?
Well, I think he did that because of how he set the line above it up.

Code: Select all

// created field here...
create field ""&testname&"" in group "mainbox" 
move it to 158,myPosition1
// repeated it here...
put tArray["users"][myID]["idnumber"] into field ""&testname&""
The way it is written looks funny, but I don't think the name itself is the reason since he has ampersands on both sides. If you wrote it with spaces, it would look more normal -
field "" & testname & ""

But you are certainly correct, it could be shortened to just field testname, provided 'testname' is a variable holding something else, if it is the actual name you want the field to be it should be field "testname".

*Edit - this was only an explanation to bangkok, not a solution to the problem. I see some other issues, but will take a bit to test those out before commenting.

*Edit for clarity - I think the reason the field name errors out is because you are naming them strictly with numbers. In Lc, field 10 would refer to the 10th field created, it is not a way to name the field.
Last edited by bogs on Fri Apr 27, 2018 4:43 pm, edited 1 time in total.
Image

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: JSON ERROR

Post by bogs » Fri Apr 27, 2018 4:23 pm

Well, I only had time to briefly look at / test this, but I've made some corrections to the code posted, which I've commented.

Code: Select all

on mouseup
/* Previous code created this group over and over. This creates the group once,
 and puts any controls created into a variable which can be checked during the loop...*/
   if there is not a group "mainbox" then create group "mainbox"
   put the childControlNames of group "mainbox" into tmpCtrlNames
   
   put 0 into myLoop
   put 242 into myPosition1
   put 1 into myID
   put 0 into testname
   
   repeat until myLoop = 5
      
      add 1 to myLoop
      add 50 to myPosition1
      add 1 to myID
      add 10 to testname
      if there is group "mainbox" then
/* We are testing to see if it is necessary to create a field or not...*/
         if testname is among the lines of tmpCtrlNames then
            // don't create it, it already exists...
         else
         // it isn't there, so create it...
            create field testname in group "mainbox"
            move group "mainbox" to 158,myPosition1
         end if
      end if
/* No array was created in the previous code above, so there is nothing to put into
   any of the fields. If you have a handler somewhere else creating the array, you 
   can un-comment this next line ... */
    //  put tArray["users"][myID]["idnumber"] into field testname
   end repeat
Hope that is of some help to you.
Image

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: JSON ERROR

Post by bogs » Fri Apr 27, 2018 5:00 pm

Corrected some flaws in my above code -

Code: Select all

on mouseup
   if there is not a group "mainbox" then create group "mainbox"
   put the childControlNames of group "mainbox" into tmpCtrlNames
   
   put 0 into myLoop
   put 242 into myPosition1
   put 1 into myID
   put 0 into testname
   
   repeat until myLoop = 5
      
      add 1 to myLoop
      add 50 to myPosition1
      add 1 to tArray[myID]
      
      add 10 to testname
      if there is group "mainbox" then
         if testname is among the lines of tmpCtrlNames then
            // don't create it, it already exists...
         else
            create field testname in group "mainbox"
            move group "mainbox" to 158,myPosition1
         end if
      end if
      // put tArray["users"]["myID"]["idnumber"] into field testname
      put "users idnumber " & tArray[myID] into field myLoop      
   end repeat
   
end mouseup

Some things to note -
  • The above code does not fix the issue with naming the fields, only allows it to work as intended.
  • Grammatical correction for the layout of the field entry at the end put in.
  • Time for lunch :shock:
Good luck with it :)
Image

Post Reply

Return to “Talking LiveCode”