From b3c71fef9e88e230e41c8b0dc488411f9f74644b Mon Sep 17 00:00:00 2001 From: Tom Robinson Date: Tue, 6 Jan 2009 17:10:22 +0800 Subject: [PATCH] Simpler JSON APIs as CPString class/instance methods. Signed-off-by: Tom Robinson --- Foundation/CPString.j | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/Foundation/CPString.j b/Foundation/CPString.j index 3de11401b..da652a73b 100644 --- a/Foundation/CPString.j +++ b/Foundation/CPString.j @@ -23,6 +23,7 @@ @import "CPObject.j" @import "CPException.j" @import "CPSortDescriptor.j" +@import "CPValue.j" /*! @@ -640,4 +641,24 @@ var CPStringHashes = new objj_dictionary(); @end +@implementation CPString (JSON) + +/*! + Returns a string representing the supplied JavaScript object encoded as JSON. +*/ ++ (CPString)encodeJSON:(JSObject)anObject +{ + return CPJSObjectCreateJSON(anObject); +} + +/*! + Returns a JavaScript object decoded from the string's JSON representation. +*/ +- (JSObject)decodeJSON +{ + return CPJSObjectCreateWithJSON(self); +} + +@end + String.prototype.isa = CPString;