It is currently April 30th, 2024, 12:24 pm

How do you deal with JSON Arrays in Rainmeter?

Get help with creating, editing & fixing problems with skins
AqilCont
Posts: 6
Joined: August 19th, 2019, 12:44 am

How do you deal with JSON Arrays in Rainmeter?

Post by AqilCont »

I was trying to make a skin where data is gotten from the osu! website and displayed on the desktop so you can check it anytime you want to. The problem is, that I am trying to get the TOP play from a series of plays which is housed in an array in the code:

Code: Select all

{"scoresBest":[
	{"id":2874200572,"user_id":12443057,"accuracy":0.9373156342182891,"mods":[],"score":1759672,"max_combo":323,"perfect":false,"statistics":{"count_50":1,"count_100":14,"count_300":207,"count_geki":56,"count_katu":12,"count_miss":4},"pp":109.929,"rank":"A","created_at":"2019-08-16T22:28:54+00:00","mode":"osu","mode_int":0,"replay":false,"beatmap":{"id":1973474,"beatmapset_id":944993,"mode":"osu","mode_int":0,"convert":null,"difficulty_rating":5.35767,"version":"Expert","total_length":92,"hit_length":88,"cs":4,"drain":5.3,"accuracy":8.3,"ar":9,"playcount":284004,"passcount":51147,"count_circles":127,"count_sliders":99,"count_spinners":0,"count_total":325,"last_updated":"2019-04-07T00:25:17+00:00","ranked":1,"status":"ranked","url":"https:\/\/osu.ppy.sh\/beatmaps\/1973474","deleted_at":null},"beatmapset":{"id":944993,"title":"Chikatto Chika Chika (TV Size)","artist":"Fujiwara Chika (CV: Kohara Konomi)","creator":"Affirmation","user_id":6186628,"covers":{"cover":"https:\/\/assets.ppy.sh\/beatmaps\/944993\/covers\/cover.jpg?1554596747","cover@2x":"https:\/\/assets.ppy.sh\/beatmaps\/944993\/covers\/cover@2x.jpg?1554596747","card":"https:\/\/assets.ppy.sh\/beatmaps\/944993\/covers\/card.jpg?1554596747","card@2x":"https:\/\/assets.ppy.sh\/beatmaps\/944993\/covers\/card@2x.jpg?1554596747","list":"https:\/\/assets.ppy.sh\/beatmaps\/944993\/covers\/list.jpg?1554596747","list@2x":"https:\/\/assets.ppy.sh\/beatmaps\/944993\/covers\/list@2x.jpg?1554596747","slimcover":"https:\/\/assets.ppy.sh\/beatmaps\/944993\/covers\/slimcover.jpg?1554596747","slimcover@2x":"https:\/\/assets.ppy.sh\/beatmaps\/944993\/covers\/slimcover@2x.jpg?1554596747"},"favourite_count":397,"play_count":1128285,"preview_url":"\/\/b.ppy.sh\/preview\/944993.mp3","video":true,"source":"Kaguya-sama: Love Is War","status":"ranked"},"weight":{"percentage":100,"pp":109.929},"user":{"id":12443057,"username":"AqilCont","profile_colour":null,"avatar_url":"https:\/\/a.ppy.sh\/12443057?1544392175.jpeg","country_code":"US","default_group":"default","is_active":true,"is_bot":false,"is_online":false,"is_supporter":false,"last_visit":"2019-08-19T22:59:00+00:00","pm_friends_only":false}
}, ........
How do I do it? Whenever I put .* anywhere, it pulls up an error saying there was a problem getting the matches. I want to get the accuracy, mods, score, max_combo, pp, rank, title, and "covers":{"covers": attributes of the first object(in order). Is this even possible or will I have to manage without it?
Last edited by AqilCont on August 20th, 2019, 10:58 pm, edited 1 time in total.
User avatar
eclectic-tech
Rainmeter Sage
Posts: 5407
Joined: April 12th, 2012, 9:40 pm
Location: Cedar Point, Ohio, USA

Re: How do you deal with JSON Arrays in Rainmeter?

Post by eclectic-tech »

AqilCont wrote: August 19th, 2019, 11:37 pm I was trying to make a skin where data is gotten from the osu! website and displayed on the desktop so you can check it anytime you want to. The problem is, that I am trying to get the TOP play from a series of plays which is housed in an array in the code:
,,,
How do I do it? Whenever I put .* anywhere, it pulls up an error saying there was a problem getting the matches. I want to get the accuracy, mods, score, max_combo, pp, rank, title, and "covers":{"covers": attributes of the first object(in order). Is this even possible or will I have to manage without it?
For the code you posted, you need to "escape" RegExp Reserve characters in the code using a backslash \

This RegExp will return the StringIndexes listed below (in the same order as your request):

Code: Select all

RegExp=(?siU).*\{"scoresBest":\[.*\{"id":2874200572,"user_id":12443057,"accuracy":(.*),.*"mods":(.*),"score":(.*),"max_combo":(.*),.*"pp":(.*),"rank":"(.*)".*"title":"(.*)".*"artist":"(.*)".*"covers":\{"cover":"(.*)".*"cover@2x":"(.*)".*"card":"(.*)".*"card@2x":"(.*)".*"list":"(.*)".*"list@2x":"(.*)".*"slimcover":"(.*)".*"slimcover@2x":"(.*)"\},
StringIndexes
1 => 0.9373156342182891
2 => []
3 => 1759672
4 => 323
5 => 109.929
6 => A
7 => Chikatto Chika Chika (TV Size)
8 => Fujiwara Chika (CV: Kohara Konomi)
9 => https:\/\/assets.ppy.sh\/beatmaps\/944993\/covers\/cover.jpg?1554596747
10 => https:\/\/assets.ppy.sh\/beatmaps\/944993\/covers\/cover@2x.jpg?1554596747
11 => https:\/\/assets.ppy.sh\/beatmaps\/944993\/covers\/card.jpg?1554596747
12 => https:\/\/assets.ppy.sh\/beatmaps\/944993\/covers\/card@2x.jpg?1554596747
13 => https:\/\/assets.ppy.sh\/beatmaps\/944993\/covers\/list.jpg?1554596747
14 => https:\/\/assets.ppy.sh\/beatmaps\/944993\/covers\/list@2x.jpg?1554596747
15 => https:\/\/assets.ppy.sh\/beatmaps\/944993\/covers\/slimcover.jpg?1554596747
16 => https:\/\/assets.ppy.sh\/beatmaps\/944993\/covers\/slimcover@2x.jpg?1554596747
AqilCont
Posts: 6
Joined: August 19th, 2019, 12:44 am

Re: How do you deal with JSON Arrays in Rainmeter?

Post by AqilCont »

I have tried this before, and it always returns an error. (sorry, but the data i gave you was only 1 part of the array)
Image
You do not have the required permissions to view the files attached to this post.
User avatar
FreeRaider
Posts: 826
Joined: November 20th, 2012, 11:58 pm

Re: How do you deal with JSON Arrays in Rainmeter?

Post by FreeRaider »

AqilCont wrote: August 19th, 2019, 11:37 pmI want to get the accuracy, mods, score, max_combo, pp, rank, title, and "covers":{"covers": attributes of the first object(in order). Is this even possible or will I have to manage without it?
AqilCont wrote: August 20th, 2019, 9:46 pm I have tried this before, and it always returns an error. (sorry, but the data i gave you was only 1 part of the array)
Image

If "id":2874200572 and "user_id":12443057 are different or they are useless, you have to remove them from eclectic-tech's code

It will be

Code: Select all

RegExp=(?siU).*\{"scoresBest":\[.*\{"id":.*,"user_id":.*,"accuracy":(.*),.*"mods":(.*),"score":(.*),"max_combo":(.*),.*"pp":(.*),"rank":"(.*)".*"title":"(.*)".*"artist":"(.*)".*"covers":\{"cover":"(.*)".*"cover@2x":"(.*)".*"card":"(.*)".*"card@2x":"(.*)".*"list":"(.*)".*"list@2x":"(.*)".*"slimcover":"(.*)".*"slimcover@2x":"(.*)"\},
AqilCont
Posts: 6
Joined: August 19th, 2019, 12:44 am

Re: How do you deal with JSON Arrays in Rainmeter?

Post by AqilCont »

Wow, that worked! Thank you so much, really appreciated the help! :D
User avatar
FreeRaider
Posts: 826
Joined: November 20th, 2012, 11:58 pm

Re: How do you deal with JSON Arrays in Rainmeter?

Post by FreeRaider »

AqilCont wrote: August 20th, 2019, 10:57 pm Wow, that worked! Thank you so much, really appreciated the help! :D
Glad to help, but the credit belongs to eclectic-tech.