1

Reading JSON in java

(19/10/2017 03:40:25 отредактировано Denisse)

Тема: Reading JSON in java

Hello,
I have two questions about the Wialon Java API.

How can I validate the null data in the following parameter?

System.out.println("params: " + ((Unit)item).getMessageParams());

Output when the value is null I get the following answer:

Output:  params:null

The second question is: when do you get the parameter values as the next answer, how can I read only the value with "v"?

Output: params: {adc1={v=0.0, ct=1.508226655E9, at=1.508372739E9}, cell_id={v=1.38685781E8, ct=1.508370039E9, at=1.508372739E9}, engine={v=0.0, ct=1.508366316E9, at=1.508372739E9}......

For example, if the code have the next sentence:

System.out.println("engine: " + ((Unit)item).getMessageParams().get("odometer"));

The Output is: {v=0.0, ct=1.508366316E9, at=1.508372739E9}

But, I need the value "v=0.0", Can you help me, please?

I wait comments or ideas.

Thank you very much.

2

Reading JSON in java

Re: Reading JSON in java

Hello, Denisse.

Denisse пишет:

How can I validate the null data in the following parameter?

if (item!= null && item instanceof Unit && ((Unit)item).getMessageParams()!=null)
                System.out.println("params: " + ((Unit)item).getMessageParams());
Denisse пишет:

But, I need the value "v=0.0", Can you help me, please?

if (item!= null && item instanceof Unit && ((Unit)item).getMessageParams()!=null) {
                Object odometer=((Unit)item).getMessageParams().get("odometer");
                if (odometer!=null && odometer instanceof Map && ((Map) odometer).containsKey("v"))
                    System.out.println("odometer: " + ((Map)odometer).get("v"));
            }
Mobile Development
Gurtam
3

Reading JSON in java

Re: Reading JSON in java

kopa
Thank you very much for this information.