在java中的JSON解析

问题描述:

我不知道如何解析java中的JSON(或其他任何东西)。我看过一些教程,但我无法弄清楚。我想要获得title="Fabiola Jean and Laurent Lundy commented on a photo that you're tagged"。所有我需要的是知道如何创建一个getTitle()方法 这就是我要解析JSON:在java中的JSON解析

Connection[data=[Notification[id=notif__161136848 metadata=null 
title=Fabiola Jean and Laurent Lundy commented on a photo that you're tagged in. type=null]] 

nextPageUrl=https://graph.facebook.com/811204509/notifications?fields 
    =title&value=1&format=json&redirect=1&access_token=MY_TOKEN&__paging_token= 
    notif__161136848 

    previousPageUrl=https://graph.facebook.com/811204509/notifications?fields=title 
&value=1&format=json&redirect=1&access_token=MY_TOKEN&limit=5000&since=1342109329& 
      __paging_token=notif__161136848&__previous=1 next=true previous=true] 
+1

检查[gson](http://code.google.com/p/google-gson/) – higuaro 2012-07-13 04:44:14

+1

你可以把json响应吗? – Suresh 2012-07-13 04:54:11

+3

这看起来不像JSON字符串。 – cgull 2012-07-13 04:56:22

首先,你把你的问题的代码是完全无效的JSON。我不太确定它是什么,它似乎不容易被解析。

假设您尝试解析实际的JSON,您几乎可以肯定希望使用第三方库而不是使用字符串操作函数编写代码。

Gson将是我的第一个建议,并Jackson是你可能想看看另一种选择。

+0

当我尝试使用restFb从Facebook获得我的通知时,返回的是JSon。谢谢,我会看看GSON – MrChery 2012-07-13 05:33:55