1

我不知道如何在 java(或其他任何东西)中解析 JSON。我看过一些教程,但我无法直截了当。

我试图得到title="Fabiola Jean and Laurent Lundy commented on a photo that you're tagged". 我只需要知道如何创建一个 getTitle() 方法,这是我要解析的 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]
4

1 回答 1

3

首先,您在问题中输入的代码绝对不是有效的 JSON。我不太确定它是什么,而且它似乎不容易解析。

假设您正在尝试解析实际的 JSON,您几乎肯定想要使用 3rd 方库而不是使用字符串操作函数编写代码。

Gson将是我的第一个推荐,而Jackson是您可能想要考虑的另一个选择。

于 2012-07-13T05:04:18.280 回答