NSObject+AGSSBJson.h has been removed from v100 ??
how can we use ags_JSONRepresentation ??
SBJson was a third party library that has no longer been necessary the last few years now that Apple has shipped NSJSONSerialization. Objects that support AGSJSONSerializable have a toJSON method you can call. That will give you a JSON object (most likely an NSDictionary, but could be an NSArray). You can use that JSON object with NSJSONSerialization to get NSData:
AGSObject -> NSDictionary -> NSJSONSerialization -> NSData
You can also go the other way if you have NSData:
NSData -> NSJSONSerialization -> NSDictionary -> AGSObject
Here is sample code showing you how to do both:
<SPAN class="operator token">-</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">void</SPAN><SPAN class="punctuation token">)</SPAN>testJSONSerialization<SPAN class="punctuation token">{</SPAN> <SPAN class="comment token">// Example 1: AGSPoint to NSData of JSON string...</SPAN> <SPAN class="comment token">//</SPAN> AGSPoint <SPAN class="operator token">*</SPAN>point <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN>AGSPoint pointWithX<SPAN class="punctuation token">:</SPAN><SPAN class="number token">34</SPAN> y<SPAN class="punctuation token">:</SPAN><SPAN class="operator token">-</SPAN><SPAN class="number token">117</SPAN> spatialReference<SPAN class="punctuation token">:</SPAN><SPAN class="punctuation token">[</SPAN>AGSSpatialReference WGS84<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">;</SPAN> id jsonObject <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN>point toJSON<SPAN class="punctuation token">:</SPAN>nil<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">;</SPAN> NSData <SPAN class="operator token">*</SPAN>data <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN>NSJSONSerialization dataWithJSONObject<SPAN class="punctuation token">:</SPAN>jsonObject options<SPAN class="punctuation token">:</SPAN><SPAN class="number token">0</SPAN> error<SPAN class="punctuation token">:</SPAN>nil<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="comment token">// do whatever you want with the NSData...</SPAN> <SPAN class="comment token">// ...</SPAN> <SPAN class="comment token">// ...</SPAN> <SPAN class="comment token">// For example print out a json string:</SPAN> <SPAN class="token function">NSLog</SPAN><SPAN class="punctuation token">(</SPAN>@<SPAN class="string token">"the json string: %@"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="punctuation token">[</SPAN>NSString alloc<SPAN class="punctuation token">]</SPAN>initWithData<SPAN class="punctuation token">:</SPAN>data encoding<SPAN class="punctuation token">:</SPAN>NSUTF8StringEncoding<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="comment token">// Example 2: NSData of JSON String to AGSPoint</SPAN> <SPAN class="comment token">//</SPAN> id jsonObject2 <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN>NSJSONSerialization JSONObjectWithData<SPAN class="punctuation token">:</SPAN>data options<SPAN class="punctuation token">:</SPAN><SPAN class="number token">0</SPAN> error<SPAN class="punctuation token">:</SPAN>nil<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">;</SPAN> AGSPoint <SPAN class="operator token">*</SPAN>point2 <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">(</SPAN>AGSPoint<SPAN class="operator token">*</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">[</SPAN>AGSPoint fromJSON<SPAN class="punctuation token">:</SPAN>jsonObject2 error<SPAN class="punctuation token">:</SPAN>nil<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="comment token">// print out and test for equality</SPAN> <SPAN class="token function">NSLog</SPAN><SPAN class="punctuation token">(</SPAN>@<SPAN class="string token">"point1: %@"</SPAN><SPAN class="punctuation token">,</SPAN> point<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="token function">NSLog</SPAN><SPAN class="punctuation token">(</SPAN>@<SPAN class="string token">"point2: %@"</SPAN><SPAN class="punctuation token">,</SPAN> point2<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="token function">NSAssert</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">[</SPAN>point isEqualToGeometry<SPAN class="punctuation token">:</SPAN>point2<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> @<SPAN class="string token">"point comparison failed..."</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="punctuation token">}</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
Thank you so much
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.