File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Java Representation of JSON String Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Java Representation of JSON String" Watch "Java Representation of JSON String" New topic
Author

Java Representation of JSON String

Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

I'm trying to create a transport object in Java for a json string. I'm using jqGrid which is a jquery plugin and it accepts a json string representing the data in the table. Up to now I've hand coded the bits to take the data I need and construct the json String. I need to create a JavaBean that I can use a JSON library on to make things easier. But the json string I am dealing with is making me wonder if it is even going to be possible.



That is a short example of the format of the json. Any help is appreciated. If I get something close in the mean time I'll post back.


GenRocket - Experts at Building Test Data
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Here's what I've got so far:




Populating the data with a single row I get:



It's not too far off but I don't need the class names. That might just be an API issue.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Actually, I think if I can get rid of the class values, I'll have what I need.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Yep, adjusting the json library to exclude the "class" was all that was left. Problem solved.
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Anything else you need?
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
I notice that in the original sample input, total appears to be an integer, and everything else is a string. In your generated output, total is a string, and id is an integer. Don't know if it matters, but it may cause some mismatch problems later. Or not.


"I'm not back." - Bill Harding, Twister
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Originally posted by Jim Yingst:
I notice that in the original sample input, total appears to be an integer, and everything else is a string. In your generated output, total is a string, and id is an integer. Don't know if it matters, but it may cause some mismatch problems later. Or not.


Thanks Jim. It doesn't seem to matter at the moment. I've blogged about the whole thing here.
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
I see. So this was all just a ploy to pimp your blog. Got it.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Originally posted by Jim Yingst:
I see. So this was all just a ploy to pimp your blog. Got it.


Darn. Busted.
vicky kumar
Ranch Hand

Joined: Dec 13, 2002
Posts: 55
Hi Gregg,
I read your blog and found out that you converted the Java Bean into JqGrid specific JSON string using FlexJSON which is build on Java 1.5. Is there any way I can do the same using JDK1.4? FlexJSON doesn't 1.5 binaries.
Please suggest...

Thanks
Vicky
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

Hi Vicky,

You might get more luck posting your question in a new thread as we try not to WakeTheZombies


Cheers, Martijn - Blog,
Twitter, PCGen, Ikasan, My The Well-Grounded Java Developer book!,
My start-up.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java Representation of JSON String