Raised This Month: $12 Target: $400
 3% 

Solved Read JSON with dot notation in key


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
RaZ_HU
Senior Member
Join Date: May 2015
Location: Hungary
Old 11-06-2018 , 11:07   Read JSON with dot notation in key
Reply With Quote #1

I'm new, I mean really NEW to JSON so I can't figure it out how can I get the values from keys under a dot notated "key"?

JSON file format:
Code:
{
	"text1": "result1",
	"XXX.XXX": {
			"text2": "result2"
	}
}
So I can retrieve text1 data (result1) with this:
Code:
json_object_get_string(object, "text1", data, charsmax(data)
But this won't work because dot notation in the key:
Code:
json_object_get_string(object, "XXX.XXX.text2", data, charsmax(data)
Can someone write a plugin that reads all of those and stores it to an array?

Last edited by RaZ_HU; 11-06-2018 at 16:33.
RaZ_HU is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 11-06-2018 , 11:12   Re: Read JSON with dot notation in key
Reply With Quote #2

If the key has dots then you can't use the dot notation, it even says so in the doc. First retrieve the "XXX.XXX" object using json_object_get_value, then retrieve the property from that object.
__________________
klippy is offline
RaZ_HU
Senior Member
Join Date: May 2015
Location: Hungary
Old 11-06-2018 , 14:33   Re: Read JSON with dot notation in key
Reply With Quote #3

Oh hell, got it thanks.
Just had a look at return of get_value

Last edited by RaZ_HU; 11-06-2018 at 16:32.
RaZ_HU is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 11:00.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode