From 852f9b67ab0abb753295ae7c016781ffd1214231 Mon Sep 17 00:00:00 2001 From: fangq <fangq@786e58fb-9377-0410-9ff7-e4ac0ac0635c> Date: Fri, 1 Jun 2012 04:03:02 +0000 Subject: [PATCH] support JSONP in savejson git-svn-id: http://svn.code.sf.net/p/iso2mesh/code/trunk/jsonlab@370 786e58fb-9377-0410-9ff7-e4ac0ac0635c --- savejson.m | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/savejson.m b/savejson.m index 24b671c..da6431d 100644 --- a/savejson.m +++ b/savejson.m @@ -54,6 +54,9 @@ function json=savejson(rootname,obj,varargin) % 1e999 to represent Inf, they can set opt.Inf to '$11e999' % opt.NaN ['"_NaN_"'|string]: a customized regular expression pattern % to represent NaN +% opt.JSONP [''|string]: to generate a JSONP output (JSON with padding), +% for example, if opt.JSON='foo', the JSON data is +% wrapped inside a function call as 'foo(...);' % opt can be replaced by a list of ('param',value) pairs. The param % string is equivallent to a field in opt. % output: @@ -98,6 +101,11 @@ else json=sprintf('{\n%s\n}\n',json); end +jsonp=jsonopt('JSONP','',opt); +if(~isempty(jsonp)) + json=sprintf('%s(%s);\n',jsonp,json); +end + % save to a file if FileName is set, suggested by Patrick Rapin if(~isempty(jsonopt('FileName','',opt))) fid = fopen(opt.FileName, 'wt'); -- GitLab