I have a JSON - File with an Array, and have problems to find the right way to loop through the array.
I downloaded the “XOJO User Guide Book 3 Framework” in the Apple iBook Store, because of the JSON Chapter. But I didn’t get it, how to parse Arrays in JSONs.
My JSON is this one:
[code]{
“d”: {
“results”: [12]
0: {
“__metadata”: {
“id”: “http://127.0.0.1:8080/PaymentBehaviourCollection(CustomerNo=‘0000801120’,CompanyCode=‘1000’,Year=‘2015’,Month=‘04’)”
“uri”: “http://127.0.0.1:8080/PaymentBehaviourCollection(CustomerNo=‘0000801120’,CompanyCode=‘1000’,Year=‘2015’,Month=‘04’)”
“type”: “fincustfactsheet.PaymentBehaviour”
}-
“CustomerNo”: “0000801120”
“CompanyCode”: “1000”
“Year”: “2015”
“Month”: “04”
“AverageDaysInArrears”: “-2”
}-
1: {
“__metadata”: {
“id”: “http://127.0.0.1:8080/PaymentBehaviourCollection(CustomerNo=‘0000801120’,CompanyCode=‘1000’,Year=‘2015’,Month=‘02’)”
“uri”: “http://127.0.0.1:8080/PaymentBehaviourCollection(CustomerNo=‘0000801120’,CompanyCode=‘1000’,Year=‘2015’,Month=‘02’)”
“type”: “fincustfactsheet.PaymentBehaviour”
}-
“CustomerNo”: “0000801120”
“CompanyCode”: “1000”
“Year”: “2015”
“Month”: “02”
“AverageDaysInArrears”: “-3”
}-
2: {
“__metadata”: {
“id”: “http://127.0.0.1:8080/PaymentBehaviourCollection(CustomerNo=‘0000801120’,CompanyCode=‘1000’,Year=‘2015’,Month=‘01’)”
“uri”: “http://127.0.0.1:8080/PaymentBehaviourCollection(CustomerNo=‘0000801120’,CompanyCode=‘1000’,Year=‘2015’,Month=‘01’)”
“type”: “fincustfactsheet.PaymentBehaviour”
}-
“CustomerNo”: “0000801120”
“CompanyCode”: “1000”
“Year”: “2015”
“Month”: “01”
“AverageDaysInArrears”: “-5”
}-
3: {
“__metadata”: {
“id”: “http://127.0.0.1:8080/PaymentBehaviourCollection(CustomerNo=‘0000801120’,CompanyCode=‘1000’,Year=‘2014’,Month=‘12’)”
“uri”: “http://127.0.0.1:8080/PaymentBehaviourCollection(CustomerNo=‘0000801120’,CompanyCode=‘1000’,Year=‘2014’,Month=‘12’)”
“type”: “fincustfactsheet.PaymentBehaviour”
}-
“CustomerNo”: “0000801120”
“CompanyCode”: “1000”
“Year”: “2014”
“Month”: “12”
“AverageDaysInArrears”: “-2”
}-
4: {
“__metadata”: {
“id”: “http://127.0.0.1:8080/PaymentBehaviourCollection(CustomerNo=‘0000801120’,CompanyCode=‘1000’,Year=‘2014’,Month=‘11’)”
“uri”: “http://127.0.0.1:8080/PaymentBehaviourCollection(CustomerNo=‘0000801120’,CompanyCode=‘1000’,Year=‘2014’,Month=‘11’)”
“type”: “fincustfactsheet.PaymentBehaviour”
}-
“CustomerNo”: “0000801120”
“CompanyCode”: “1000”
“Year”: “2014”
“Month”: “11”
“AverageDaysInArrears”: “-1”
}-
5: {
“__metadata”: {
“id”: “http://127.0.0.1:8080/PaymentBehaviourCollection(CustomerNo=‘0000801120’,CompanyCode=‘1000’,Year=‘2014’,Month=‘10’)”
“uri”: “http://127.0.0.1:8080/PaymentBehaviourCollection(CustomerNo=‘0000801120’,CompanyCode=‘1000’,Year=‘2014’,Month=‘10’)”
“type”: “fincustfactsheet.PaymentBehaviour”
}-
“CustomerNo”: “0000801120”
“CompanyCode”: “1000”
“Year”: “2014”
“Month”: “10”
“AverageDaysInArrears”: “-6”
}-
6: {
“__metadata”: {
“id”: “http://127.0.0.1:8080/PaymentBehaviourCollection(CustomerNo=‘0000801120’,CompanyCode=‘1000’,Year=‘2014’,Month=‘09’)”
“uri”: “http://127.0.0.1:8080/PaymentBehaviourCollection(CustomerNo=‘0000801120’,CompanyCode=‘1000’,Year=‘2014’,Month=‘09’)”
“type”: “fincustfactsheet.PaymentBehaviour”
}-
“CustomerNo”: “0000801120”
“CompanyCode”: “1000”
“Year”: “2014”
“Month”: “09”
“AverageDaysInArrears”: “-2”
}-
7: {
“__metadata”: {
“id”: “http://127.0.0.1:8080/PaymentBehaviourCollection(CustomerNo=‘0000801120’,CompanyCode=‘1000’,Year=‘2014’,Month=‘08’)”
“uri”: “http://127.0.0.1:8080/PaymentBehaviourCollection(CustomerNo=‘0000801120’,CompanyCode=‘1000’,Year=‘2014’,Month=‘08’)”
“type”: “fincustfactsheet.PaymentBehaviour”
}-
“CustomerNo”: “0000801120”
“CompanyCode”: “1000”
“Year”: “2014”
“Month”: “08”
“AverageDaysInArrears”: “-4”
}-
8: {
“__metadata”: {
“id”: “http://127.0.0.1:8080/PaymentBehaviourCollection(CustomerNo=‘0000801120’,CompanyCode=‘1000’,Year=‘2014’,Month=‘07’)”
“uri”: “http://127.0.0.1:8080/PaymentBehaviourCollection(CustomerNo=‘0000801120’,CompanyCode=‘1000’,Year=‘2014’,Month=‘07’)”
“type”: “fincustfactsheet.PaymentBehaviour”
}-
“CustomerNo”: “0000801120”
“CompanyCode”: “1000”
“Year”: “2014”
“Month”: “07”
“AverageDaysInArrears”: “1”
}-
9: {
“__metadata”: {
“id”: “http://127.0.0.1:8080/PaymentBehaviourCollection(CustomerNo=‘0000801120’,CompanyCode=‘1000’,Year=‘2014’,Month=‘06’)”
“uri”: “http://127.0.0.1:8080/PaymentBehaviourCollection(CustomerNo=‘0000801120’,CompanyCode=‘1000’,Year=‘2014’,Month=‘06’)”
“type”: “fincustfactsheet.PaymentBehaviour”
}-
“CustomerNo”: “0000801120”
“CompanyCode”: “1000”
“Year”: “2014”
“Month”: “06”
“AverageDaysInArrears”: “-2”
}-
10: {
“__metadata”: {
“id”: “http://127.0.0.1:8080/PaymentBehaviourCollection(CustomerNo=‘0000801120’,CompanyCode=‘1000’,Year=‘2014’,Month=‘05’)”
“uri”: “http://127.0.0.1:8080/PaymentBehaviourCollection(CustomerNo=‘0000801120’,CompanyCode=‘1000’,Year=‘2014’,Month=‘05’)”
“type”: “fincustfactsheet.PaymentBehaviour”
}-
“CustomerNo”: “0000801120”
“CompanyCode”: “1000”
“Year”: “2014”
“Month”: “05”
“AverageDaysInArrears”: “-3”
}-
11: {
“__metadata”: {
“id”: “http://127.0.0.1:8080/PaymentBehaviourCollection(CustomerNo=‘0000801120’,CompanyCode=‘1000’,Year=‘2014’,Month=‘04’)”
“uri”: “http://127.0.0.1:8080/PaymentBehaviourCollection(CustomerNo=‘0000801120’,CompanyCode=‘1000’,Year=‘2014’,Month=‘04’)”
“type”: “fincustfactsheet.PaymentBehaviour”
}-
“CustomerNo”: “0000801120”
“CompanyCode”: “1000”
“Year”: “2014”
“Month”: “04”
“AverageDaysInArrears”: “-3”
}-
}-
}[/code]
I want to get the Months, and AverageDaysInArrears.
For the AverageDaysInArreas I tried a lot of ways. I think it have to be something like:
[In String_Data is the JSON]
dim root as new JSONItem( String_Data)
dim rootItem as JSONItem = root.Value( "d" )
dim readname as string = rootItem.Value( "AverageDaysInArrears" )
MsgBox( readname )
The rootItem.Value( “AverageDaysInArrears” ) crashed in the Debugger. So I try something like:
dim root as new JSONItem( String_Data)
dim rootItem as JSONItem = root.Value( "d" )
dim readname as string = rootItem.child(0).Value( "AverageDaysInArrears" )
MsgBox( readname )
But it crashed again.