help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Octave json creator


From: veryhappy
Subject: Re: Octave json creator
Date: Mon, 6 Dec 2010 02:36:09 -0800 (PST)

It's easy i just followed the specifications i found in www.json.org.In the
end I only matched data into one of those groups this way:
If it's a single element:
  function handles=>string with the name of the function
  structs=>object with the field names as strings and their content as
values
  cell=>I just used the type of the cell's content to match it
  double=> If it's real=>number
           => If it's complex=>object with "real" property=real(double) and
"imag" property=imag(double)
  char=>The value of the char as string
  other things=> the name returned by class() function as string
  string or char vector=>string with that value
If it's a vector or cell with more than one element then:
  everything but rows of chars (which are converted to strings)=>array with
their value as content     keeping the dimensions (i.e. a 2x5x4 size array
will end in an array of 2x4x5 size too)
  rows of chars=>strings
I used the compact form (i.e.: no unnecesary spaces and line breaks) over
the expanded one but it should be trivial to add a expanded one by just
replacing sep=','; with sep=",\n";
I hope this will make things a little clearer for you

BUGFIX: Where it reads:
         
json=['{"real":',num2str(real(object)),',"imag:"',num2str(imag(object)),'}'];
it should read:
         
json=['{"real":',num2str(real(object)),',"imag":',num2str(imag(object)),'}'];
(notice '"imag:"' should be 'imag":')
-- 
View this message in context: 
http://octave.1599824.n4.nabble.com/Octave-json-creator-tp3072273p3074255.html
Sent from the Octave - General mailing list archive at Nabble.com.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]