Dear, All.
I have a text file as below;
--------------------------------------------
"index": "0",
"rank": "1",
"id": "54274675",
"name": "mynameis",
"number": "000-0000-1111",
"category": [
"cate1, cate2",
"cate3"
],
"address": "here_address",
"display": "company_name",
"Panorama_1": {
"id": "39823984928",
},
"Panorama_2": {
"id": "92839892389",
},
"broadcastInfo": {
"name": null,
"menu": null
},
---------------------------------------
I show just one starting with "index": "0",
but this text has "index": "500".
Actually, I got all IDs and Names, but...
1) I hope to get just two IDs, the first & third IDs from three, except the second ID, which is in "Panorama_1": {}.
2) I hope to get just the first name, not the second name, which is in "broadcastInfo":{ }.
3) I hope to get cate1, cate2 and cate3 that are in "category": [],
Thank you for all.
Multi lines RegExMatch Topic is solved
Re: Multi lines RegExMatch
is that supposed to be a snippet from a json string(i cant tell for sure cause of the trailing commas and its general handwrittenish feel)?
if so, it would make more sense to parse it with the json lib https://github.com/cocobelgica/AutoHotkey-JSON, then access the properties ure interested in directly
that isnt to say it cant be done with pure regex, but it strikes me as odd doing so
if so, it would make more sense to parse it with the json lib https://github.com/cocobelgica/AutoHotkey-JSON, then access the properties ure interested in directly
that isnt to say it cant be done with pure regex, but it strikes me as odd doing so
Re: Multi lines RegExMatch
Thank you, swagfag for your answer.
I didn't try to apply it yet.
I've just read about it how to use, so not sure yet if it would work or not. But it seems I wanted.
I will rewrite on my result, after using it.
I really appreciate your response again.
I didn't try to apply it yet.
I've just read about it how to use, so not sure yet if it would work or not. But it seems I wanted.
I will rewrite on my result, after using it.
I really appreciate your response again.
swagfag wrote: ↑20 Oct 2018, 11:50is that supposed to be a snippet from a json string(i cant tell for sure cause of the trailing commas and its general handwrittenish feel)?
if so, it would make more sense to parse it with the json lib https://github.com/cocobelgica/AutoHotkey-JSON, then access the properties ure interested in directly
that isnt to say it cant be done with pure regex, but it strikes me as odd doing so
Re: Multi lines RegExMatch
if it is a json string:
Code: Select all
#Warn ClassOverwrite
#Include JSON.ahk
json_str =
(
{
"index": "0",
"rank": "1",
"id": "54274675",
"name": "mynameis",
"number": "000-0000-1111",
"category": [
"cate1, cate2",
"cate3"
],
"address": "here_address",
"display": "company_name",
"Panorama_1": {
"id": "39823984928"
},
"Panorama_2": {
"id": "92839892389"
},
"broadcastInfo": {
"name": null,
"menu": null
}
}
)
Obj := JSON.Load(json_str)
MsgBox % Obj.id
MsgBox % Obj.Panorama_2.id
MsgBox % Obj.broadcastInfo.name
MsgBox % Obj.category[1]
MsgBox % Obj.category[2]
Re: Multi lines RegExMatch
Thank you, swagfag for your reply.
When I applied your script with JSON.ahk, I got some parts of data that I wanted, but didn't get some parts.
I've attached the sample_json_file.txt in this post.
I can get the value of 'sort', 'page' and 'address'. ( the value of this address is 'my_address' )
But I can't do for 'index', 'name' and 'address' in list. ( the value of this address is 'user_address' )
I'm not sure but I just guessed it is related with the depth of JSON.
Actually, the file I've uploaded has just one index, but the real file I will use has over 500 index.
If I could get the data I didn't get in my script, should I use 'for' loop to get all value for 500 index?
Thank you again. Really appreciated your efforts.
When I applied your script with JSON.ahk, I got some parts of data that I wanted, but didn't get some parts.
I've attached the sample_json_file.txt in this post.
I can get the value of 'sort', 'page' and 'address'. ( the value of this address is 'my_address' )
But I can't do for 'index', 'name' and 'address' in list. ( the value of this address is 'user_address' )
Code: Select all
FileRead, sm_data, sample_json_file.txt
parsed := JSON.Load(sm_data)
MsgBox, % parsed.result.site.sort ; it works.
MsgBox, % parsed.result.site.page ; it works.
MsgBox, % parsed.result.address ; it works. (the value is 'my_address')
MsgBox, % parsed.result.site.list.index ; nothing
MsgBox, % parsed.result.site.list.name ; nothing
MsgBox, % parsed.result.site.list.address ; nothing (the value is 'user_address')
MsgBox, % parsed.result.site.list.streetPanorama.id ; nothing
Actually, the file I've uploaded has just one index, but the real file I will use has over 500 index.
If I could get the data I didn't get in my script, should I use 'for' loop to get all value for 500 index?
Thank you again. Really appreciated your efforts.
swagfag wrote: ↑21 Oct 2018, 07:38if it is a json string:Code: Select all
#Warn ClassOverwrite #Include JSON.ahk json_str = ( { "index": "0", "rank": "1", "id": "54274675", "name": "mynameis", "number": "000-0000-1111", "category": [ "cate1, cate2", "cate3" ], "address": "here_address", "display": "company_name", "Panorama_1": { "id": "39823984928" }, "Panorama_2": { "id": "92839892389" }, "broadcastInfo": { "name": null, "menu": null } } ) Obj := JSON.Load(json_str) MsgBox % Obj.id MsgBox % Obj.Panorama_2.id MsgBox % Obj.broadcastInfo.name MsgBox % Obj.category[1] MsgBox % Obj.category[2]
- Attachments
-
- sample_json_file.txt
- (1.9 KiB) Downloaded 25 times
Re: Multi lines RegExMatch Topic is solved
List is an array containing an object. You access it as follows: parsed.result.site.list[1].address
Re: Multi lines RegExMatch
Thank you, swagfag.
Finally, I get the result that I really wanted.
Your answer solved all of my problems related with JSON.
The script would be more simple than it using RegExMatch.
Without your help, I had to do it with RegExMatch, also I didn't get wanted result.
Thank you again!!!
Finally, I get the result that I really wanted.
Your answer solved all of my problems related with JSON.
The script would be more simple than it using RegExMatch.
Without your help, I had to do it with RegExMatch, also I didn't get wanted result.
Thank you again!!!
Who is online
Users browsing this forum: jaka1, marypoppins_1, mikeyww, OrangeCat, RussF and 137 guests