JSON - 性格问题

JSON - Character issue

我使用 RMongo 库从 mongo 数据库中提取了一些数据。我一直在毫无问题地处理数据。但是,我需要访问最初保存在数据库中的字段,如 JSON。由于 rmongodb 将数据保存为数据框,我现在有一个长度为 1 的大字符向量:

res1 = "[ { \"text\" : \"@Kayture Beyoncé jam session ?\" , \"name\" : \"beponcé \xed\xa0\xbc\xed\xbc\xbb\" , \"screenName\" : \"ColaaaaTweedy\" , \"follower\" : false , \"mentions\" : [ \"Kayture\"] , \"userTwitterId\" : \"108061963\"} , { \"text\" : \"@Kayture fucking marry me\" , \"name\" : \"George McQueen\" , \"screenName\" : \"GeorgeMcQueen12\" , \"follower\" : false , \"mentions\" : [ \"Kayture\"] , \"userTwitterId\" : \"67896750\"}]"

我需要从这个数组中提取对象的所有 "text" 属性(本例中有 2 个),但我想不出一个快速的方法。我尝试使用 strsplit,或者使用 jsonlite 从字符到 json 文件,然后列出,但它不起作用。

有什么想法吗?

谢谢!

开始
res1 = "[ { \"text\" : \"@Kayture Beyoncé jam session ?\" , \"name\" : \"beponcé \xed\xa0\xbc\xed\xbc\xbb\" , \"screenName\" : \"ColaaaaTweedy\" , \"follower\" : false , \"mentions\" : [ \"Kayture\"] , \"userTwitterId\" : \"108061963\"} , { \"text\" : \"@Kayture fucking marry me\" , \"name\" : \"George McQueen\" , \"screenName\" : \"GeorgeMcQueen12\" , \"follower\" : false , \"mentions\" : [ \"Kayture\"] , \"userTwitterId\" : \"67896750\"}]"

您可以使用 jsonlite 包中的 fromJSON() 来解析 JSON 对象。

library(jsonlite)

fromJSON(res1)

                            text           name      screenName follower mentions userTwitterId
1 @Kayture Beyoncé jam session ? beponcé í ¼í¼»   ColaaaaTweedy    FALSE  Kayture     108061963
2 @Kayture fucking marry me      George McQueen GeorgeMcQueen12    FALSE  Kayture      67896750