Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Highlighted
Contributor
Posts: 24
Registered: ‎01-06-2014
My Device: 9220
My Carrier: 9220
Accepted Solution

How to get the data type from JSON Response?

How to get the data type from JSON Response?

 

 

 

Thanks and Regards ,

SukanyaArun

Developer
Posts: 17,011
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: How to get the data type from JSON Response?

maybe this helps:
http://supportforums.blackberry.com/t5/Java-Development/Sample-Code-Implementing-JSON-in-your-applic...
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Contributor
Posts: 24
Registered: ‎01-06-2014
My Device: 9220
My Carrier: 9220

Re: How to get the data type from JSON Response?

without json library , how to get the json element datatype?

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: How to get the data type from JSON Response?

[ Edited ]

Sorry this request doesn't make sense to me.

 

Can you explain to us why you need to know the data type for an element of a JSON response, when you are not going to process that JSON response with a JSON library?

 

Perhaps you could explain what you are trying to do rather than just asking us how to do it - I suspect we have some alternative suggestions to the way you are suggesting.  .

 

But from the information presented so far, the answer to your question,

"how do you get the element data type without a JSON library?"

is

"you get a JSON Library".

 

Edit:  Just to say, in fact I misread the question, I had not understood that the poster was trying to 'type' the data using the JSON response.  I know that is what the question asked, but I didn't think that was what the OP actually wanted, since there is no typing in JSON.  Apologies.  See Simon's answer to that question later. 

Contributor
Posts: 24
Registered: ‎01-06-2014
My Device: 9220
My Carrier: 9220

Re: How to get the data type from JSON Response?

Am getting the json response , Date formate as milliseconds . I need to convert ht date format . 

 

I got the value like  /Date(milliseconds) . 

Developer
Posts: 17,011
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: How to get the data type from JSON Response?

well, that sounds like an entirely different question.

If you have a long value containing the milliseconds you can create a Date object using http://www.blackberry.com/developers/docs/7.1.0api/java/util/Date.html#Date(long)
you can format this date to a string using http://www.blackberry.com/developers/docs/7.1.0api/net/rim/device/api/i18n/SimpleDateFormat.html
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Contributor
Posts: 24
Registered: ‎01-06-2014
My Device: 9220
My Carrier: 9220

Re: How to get the data type from JSON Response?

Is it possible to get the data type?

Developer
Posts: 17,011
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: How to get the data type from JSON Response?

could you elaborate your question?

json is just a collection of strings, it does not have data types.
you have to know which string represents a number, a date etc - or treat everything as string.

if you want to have strongly typed data you should use SOAP.

In your case you most likely have a field named "date" with a string representation of a long value. Use Long.parseLong to create a long with the value, then Date(long) for a date object etc.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Contributor
Posts: 24
Registered: ‎01-06-2014
My Device: 9220
My Carrier: 9220

Re: How to get the data type from JSON Response?

Thank you for your reply. And I got the backend response format is JSON . Then I need to store the elements to Sqlite DB . 

 

1)  I need to get the service documents 

 

2) Is it possible to get the metadata???

 

3) I need to sync . Am getting value from backend  . But I dono the columns data type . 

Developer
Posts: 17,011
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: How to get the data type from JSON Response?

1) no clue what you mean with that

2) what metadata?

3) if you receive json you need to know which tag name correspondents to which value. as you store everything in sql you can just use string for everything.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter