how to calculate total value for the below JSON value U.O.M Wise in Java
up vote
0
down vote
favorite
how to calculate total value for the below JSON value U.O.M Wise in Java?
sequence can be vary. We cannot expect number of uoms and sequence of results.
i have created hashset and made unique uom.
{
value=100
uom=kg
},
{
value=200
uom=kg
},
{
value=100
uom=lt
},
{
value=100
uom=ab
},
{
value=100
uom=lt
}
Please provide some code ref
java spring-boot data-structures
add a comment |
up vote
0
down vote
favorite
how to calculate total value for the below JSON value U.O.M Wise in Java?
sequence can be vary. We cannot expect number of uoms and sequence of results.
i have created hashset and made unique uom.
{
value=100
uom=kg
},
{
value=200
uom=kg
},
{
value=100
uom=lt
},
{
value=100
uom=ab
},
{
value=100
uom=lt
}
Please provide some code ref
java spring-boot data-structures
2
That isn't valid json.
– user2478398
Nov 8 at 11:25
I've manually typed here.
– KIRITHIGAN
Nov 8 at 11:26
Ok. In any case, a lot of this depends on code you already have. Do you use Gson, do you use Jackson, do you manually parse the Json? What do you mean with 'created unique uom'? Have you got an interface which represents this and lets you transform between different values, etc.?
– user2478398
Nov 8 at 11:28
@KIRITHIGAN If I am Right, Do you want to calculate the sum of kg, lt , etc ?
– Deepak Gunasekaran
Nov 8 at 11:35
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
how to calculate total value for the below JSON value U.O.M Wise in Java?
sequence can be vary. We cannot expect number of uoms and sequence of results.
i have created hashset and made unique uom.
{
value=100
uom=kg
},
{
value=200
uom=kg
},
{
value=100
uom=lt
},
{
value=100
uom=ab
},
{
value=100
uom=lt
}
Please provide some code ref
java spring-boot data-structures
how to calculate total value for the below JSON value U.O.M Wise in Java?
sequence can be vary. We cannot expect number of uoms and sequence of results.
i have created hashset and made unique uom.
{
value=100
uom=kg
},
{
value=200
uom=kg
},
{
value=100
uom=lt
},
{
value=100
uom=ab
},
{
value=100
uom=lt
}
Please provide some code ref
java spring-boot data-structures
java spring-boot data-structures
edited Nov 8 at 15:53
Koray Tugay
8,35726109214
8,35726109214
asked Nov 8 at 11:19
KIRITHIGAN
65
65
2
That isn't valid json.
– user2478398
Nov 8 at 11:25
I've manually typed here.
– KIRITHIGAN
Nov 8 at 11:26
Ok. In any case, a lot of this depends on code you already have. Do you use Gson, do you use Jackson, do you manually parse the Json? What do you mean with 'created unique uom'? Have you got an interface which represents this and lets you transform between different values, etc.?
– user2478398
Nov 8 at 11:28
@KIRITHIGAN If I am Right, Do you want to calculate the sum of kg, lt , etc ?
– Deepak Gunasekaran
Nov 8 at 11:35
add a comment |
2
That isn't valid json.
– user2478398
Nov 8 at 11:25
I've manually typed here.
– KIRITHIGAN
Nov 8 at 11:26
Ok. In any case, a lot of this depends on code you already have. Do you use Gson, do you use Jackson, do you manually parse the Json? What do you mean with 'created unique uom'? Have you got an interface which represents this and lets you transform between different values, etc.?
– user2478398
Nov 8 at 11:28
@KIRITHIGAN If I am Right, Do you want to calculate the sum of kg, lt , etc ?
– Deepak Gunasekaran
Nov 8 at 11:35
2
2
That isn't valid json.
– user2478398
Nov 8 at 11:25
That isn't valid json.
– user2478398
Nov 8 at 11:25
I've manually typed here.
– KIRITHIGAN
Nov 8 at 11:26
I've manually typed here.
– KIRITHIGAN
Nov 8 at 11:26
Ok. In any case, a lot of this depends on code you already have. Do you use Gson, do you use Jackson, do you manually parse the Json? What do you mean with 'created unique uom'? Have you got an interface which represents this and lets you transform between different values, etc.?
– user2478398
Nov 8 at 11:28
Ok. In any case, a lot of this depends on code you already have. Do you use Gson, do you use Jackson, do you manually parse the Json? What do you mean with 'created unique uom'? Have you got an interface which represents this and lets you transform between different values, etc.?
– user2478398
Nov 8 at 11:28
@KIRITHIGAN If I am Right, Do you want to calculate the sum of kg, lt , etc ?
– Deepak Gunasekaran
Nov 8 at 11:35
@KIRITHIGAN If I am Right, Do you want to calculate the sum of kg, lt , etc ?
– Deepak Gunasekaran
Nov 8 at 11:35
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
This is not valid JSON as it uses = as keyvalue separator (change to something like this and use tools like JSONLint to validate):
[{
"value": "100",
"uom": "kg"
}, {
"value": "200",
"uom": "kg"
}, {
"value": "100",
"uom": "lt"
}, {
"value": "100",
"uom": "ab"
}, {
"value": "100",
"uom": "lt"
}
]
Even having this structure you can parse it into a collection of touples (value, uom) and then just sum everything having same uom
For example you can use this:
javax.json.JsonArray body = Json.createReader(new StringReader(YOUR_JSON_STRING)).readArray();
and read a JSON to array of touples
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
This is not valid JSON as it uses = as keyvalue separator (change to something like this and use tools like JSONLint to validate):
[{
"value": "100",
"uom": "kg"
}, {
"value": "200",
"uom": "kg"
}, {
"value": "100",
"uom": "lt"
}, {
"value": "100",
"uom": "ab"
}, {
"value": "100",
"uom": "lt"
}
]
Even having this structure you can parse it into a collection of touples (value, uom) and then just sum everything having same uom
For example you can use this:
javax.json.JsonArray body = Json.createReader(new StringReader(YOUR_JSON_STRING)).readArray();
and read a JSON to array of touples
add a comment |
up vote
1
down vote
This is not valid JSON as it uses = as keyvalue separator (change to something like this and use tools like JSONLint to validate):
[{
"value": "100",
"uom": "kg"
}, {
"value": "200",
"uom": "kg"
}, {
"value": "100",
"uom": "lt"
}, {
"value": "100",
"uom": "ab"
}, {
"value": "100",
"uom": "lt"
}
]
Even having this structure you can parse it into a collection of touples (value, uom) and then just sum everything having same uom
For example you can use this:
javax.json.JsonArray body = Json.createReader(new StringReader(YOUR_JSON_STRING)).readArray();
and read a JSON to array of touples
add a comment |
up vote
1
down vote
up vote
1
down vote
This is not valid JSON as it uses = as keyvalue separator (change to something like this and use tools like JSONLint to validate):
[{
"value": "100",
"uom": "kg"
}, {
"value": "200",
"uom": "kg"
}, {
"value": "100",
"uom": "lt"
}, {
"value": "100",
"uom": "ab"
}, {
"value": "100",
"uom": "lt"
}
]
Even having this structure you can parse it into a collection of touples (value, uom) and then just sum everything having same uom
For example you can use this:
javax.json.JsonArray body = Json.createReader(new StringReader(YOUR_JSON_STRING)).readArray();
and read a JSON to array of touples
This is not valid JSON as it uses = as keyvalue separator (change to something like this and use tools like JSONLint to validate):
[{
"value": "100",
"uom": "kg"
}, {
"value": "200",
"uom": "kg"
}, {
"value": "100",
"uom": "lt"
}, {
"value": "100",
"uom": "ab"
}, {
"value": "100",
"uom": "lt"
}
]
Even having this structure you can parse it into a collection of touples (value, uom) and then just sum everything having same uom
For example you can use this:
javax.json.JsonArray body = Json.createReader(new StringReader(YOUR_JSON_STRING)).readArray();
and read a JSON to array of touples
edited Nov 8 at 15:53
James Z
11.1k71735
11.1k71735
answered Nov 8 at 11:28
Akceptor
9031320
9031320
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53206710%2fhow-to-calculate-total-value-for-the-below-json-value-u-o-m-wise-in-java%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
That isn't valid json.
– user2478398
Nov 8 at 11:25
I've manually typed here.
– KIRITHIGAN
Nov 8 at 11:26
Ok. In any case, a lot of this depends on code you already have. Do you use Gson, do you use Jackson, do you manually parse the Json? What do you mean with 'created unique uom'? Have you got an interface which represents this and lets you transform between different values, etc.?
– user2478398
Nov 8 at 11:28
@KIRITHIGAN If I am Right, Do you want to calculate the sum of kg, lt , etc ?
– Deepak Gunasekaran
Nov 8 at 11:35