需要从JSON文件中提取ID

时间:2021-02-11 16:05:06

I have just started coding and I need to extract user ID's from a JSON file.

我刚刚开始编码,我需要从JSON文件中提取用户ID。

The ID's are mixed in with usernames and comments, and I'm not entirely sure how I can extract them so I'm left with:

ID与用户名和注释混合在一起,我不完全确定如何提取它们,所以我留下:

"pk": 12345678

"pk": 87654321

"pk": 12345678

Here is the JSON file I've been attempting to parse: http://pastebin.com/CXNe2DCT

这是我一直试图解析的JSON文件:http://pastebin.com/CXNe2DCT

Also, I was wondering if it would be possible to parse just the user ID's (iterate through the list) as every other "pk" value is a comment and I just need the user ID's, not the comment ID's.

另外,我想知道是否可以解析用户ID(遍历列表),因为每个其他“pk”值都是注释,我只需要用户ID,而不是注释ID。

The comment "pk" values are longer also.

评论“pk”值也更长。

Any help would be really appreciated!

任何帮助将非常感激!

1 个解决方案

#1


0  

I strongly recommend using a library like jQuery.

我强烈建议使用像jQuery这样的库。

jQuery.getJSON("http://pastebin.com/download.php?i=CXNe2DCT", 
    function(data) {
        for (var i=0; i<data.items.length; i++) { 
            var userId = data.items[i].user.pk;
            console.log(userId);
        }
    } 
);

#1


0  

I strongly recommend using a library like jQuery.

我强烈建议使用像jQuery这样的库。

jQuery.getJSON("http://pastebin.com/download.php?i=CXNe2DCT", 
    function(data) {
        for (var i=0; i<data.items.length; i++) { 
            var userId = data.items[i].user.pk;
            console.log(userId);
        }
    } 
);