Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD Beta Forum
oldguy2
Wizard


Joined: 17 Jun 2006
Posts: 1201

PostPosted: Sat Sep 11, 2010 2:22 pm   

GMCP and JSON Questions
 
Edit: Removed the first part of my question so it doesn't cause confusion. The answer below still provides all the info needed to answer the second part for anyone else interested.

How do I access this data? Do I us the %gmcp.data from a GMCP trigger for Char.Items.List?


Last edited by oldguy2 on Sat Sep 11, 2010 8:40 pm; edited 1 time in total
Reply with quote
Zugg
MASTER


Joined: 25 Sep 2000
Posts: 23379
Location: Colorado, USA

PostPosted: Sat Sep 11, 2010 5:03 pm   
 
The reason %json is stripping spaces is because you have not properly "escaped" the quotes. Here is your line from above:
Code:
testVar = %json("{ "location": "room", "items": [ { "id": "69016", "name": "an item name" }, ...

Notice that the %json function takes a string argument that starts with " but then you have " quotes within that string. To have " quotes within a JSON string, they must be doubled.
So the correct line would look like this:
Code:
testVar = %json("{ ""location"": ""room"", ""items"": [ { ""id"": ""69016"", ""name"": ""an item name"" }, ...

But I'm not sure why you are using %json at all. %json is really only for debugging purposes. Unless you are grabbing raw JSON data via %url from Amazon and trying to parse it, you really should never need the %json function.

If you are trying to access the GMCP data, just use it directly as a database variable:
Code:
#forall %gmcp.char.items.list.items {
  #print {%i.id}
  }

If you want to assign this entire list to a variable to use later, just use:
Code:
testVar = %gmcp.char.items.list

You should never be working directly with the string format of the JSON data. Treat it as a table.
Reply with quote
oldguy2
Wizard


Joined: 17 Jun 2006
Posts: 1201

PostPosted: Sat Sep 11, 2010 8:16 pm   
 
Well because I was testing and looking at everything.... and not escaping the quotes make sense of course. Using the %literal function should work on that right? That's what I get for sitting up until 4 am. Embarassed Anyway, I was simply trying to see what everything was doing and how I could make use of it.
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Sat Sep 11, 2010 11:20 pm   
 
%literal(), as far as I know, does not take variables as arguments. You are likely thinking of %quote(), but last time I tried to use it--which was before the JSON stuff that brought in the enforcement of "" and {}--it wasn't able to quote double-quotes (the quotes would get quoted, but then the quoting of the quotes would get expanded and CMud would still end up with "" and not quite be able to figure out what to do with it, and you'd end up with an unpredictable implicitly concatenated string.)
_________________
EDIT: I didn't like my old signature
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD Beta Forum All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net