pooja2
February 26, 2020, 3:50am
1
Below is the sample input data which is used in lua code
{
“PersonData”: {
“NRIC”: “S8400013K”,
“LoginID”: “SPF457812”,
“Name”: “Name of S8400013K”,
“CategoryType”: “PERM”,
“RankCode”: “01808”,
“TelephoneNumber”: “61239009”,
“MobileNumber”: “61239009”,
“EmailID”: “test1@gmail.com ”
},
“RolesType”: {
“Role”: [
{
“RoleID”: “12345”,
“RoleType”: “Administrator Role”
},
{
“RoleID”: “12345”,
“RoleType”: “Administrator Role”
}
]
}
}
As output is JSON file so below is the JSON template which will be used to convert input data.
{
“PersonData”: {
“NRIC”: “”
},
“RolesType”: {
“Role”: [
{
“RoleID”: “”,
“RoleType”: “”
}
]
}
}
So here RoleID and RoleType is in array.
I can receive multiple RoleID and RoleType from input data.
So i need to form json ouput based on input received.
The problem i facing that after parsing json template for the ouput.
Not able to map multiple RoleID and RoleType as json output template has only one.
“Role”: [
{
“RoleID”: “”,
“RoleType”: “”
}
]
So how can i map incoming multiple array values ?
Appreciate for any help
I read your question/problem 3 times and not sure I understand it at all. Maybe with some code it will become clearer. So I made an example and let me know what you are trying to do:
local json = require("json") local roles = {} for i = 1, 5 do local role = {} role.RoleId = 34 + i role.RoleType = "Wizard"..i roles[i] = role end local holder = {} holder.PersonData = {} holder.PersonData.NRIC = "S8400013K" holder.RoleTypes = {} holder.RoleTypes.Role = roles print(json.prettify( holder ))
and the output:
{ "PersonData":{ "NRIC":"S8400013K" }, "RoleTypes":{ "Role":[{ "RoleType":"Wizard1", "RoleId":35 },{ "RoleType":"Wizard2", "RoleId":36 },{ "RoleType":"Wizard3", "RoleId":37 },{ "RoleType":"Wizard4", "RoleId":38 },{ "RoleType":"Wizard5", "RoleId":39 }] } }
is this only used in lua code ?
sorry for the unconvenience and thanks in advance !
[color=#7a7c7d]Nox[/color] [color=#7a7c7d]Vidmate[/color] [color=#7a7c7d]VLC[/color]
Yes. Where else would you want to code this? The top portion is LUA the output is just json.
thanks agramonte !
and sorry for the dumb question lol ! i’m just new to this stuff and i’m learning
always here to help. keep asking and if I can answer I will
is this only used in lua code ?
sorry for the unconvenience and thanks in advance !
[color=#7a7c7d]Nox[/color] [color=#7a7c7d]Vidmate[/color] [color=#7a7c7d]VLC[/color]
Yes. Where else would you want to code this? The top portion is LUA the output is just json.
thanks agramonte !
and sorry for the dumb question lol ! i’m just new to this stuff and i’m learning
always here to help. keep asking and if I can answer I will