Git Product home page Git Product logo

json-sans-eval's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

json-sans-eval's Issues

Traversing multiple json results

Hi there

Love the toolkit, thanks a million for making it available. I'm using the 
Blackberry version in a Widget I'm creating and have a query regarding parsing 
multiple results:

Say for example we have a json string being returned as:

{ {"id":"1","title":"row 1"} , {"id":"2","title":"row 2"} }

When I run it through jsonParse I try to access each position of results as if 
it were an array (as I saw mentioned on another issue of a similar nature):

var events = jsonParse(result);
alert(events[0].id);

and to see how many results have been returned:

alert(events.length);

but each of these returns "undefined".

I realise I'm probably doing something really dumb or missing an obvious 
solution but at the moment I'm stumped. Note that in my specific case, using 
the "for(var x in y)" approach will not fit in to my code.

Any thoughts?

Cheers

Lee

Original issue reported on code.google.com by [email protected] on 3 Jul 2010 at 1:52

Conditional operator for Json Query

What steps will reproduce the problem?
1. I have an issue with Json query. 
2. I am using Javascript, json and dojo for display. I have a grid where i 
display a set of records.
3.I have filter option where i can customize by giving my own filter.
4.If i give constructing json query like != as <> and *a* , it is working fine.
5.My requirement is to filter !=*a* which means it should return string which 
doesnt have letter 'a'.


What is the expected output? What do you see instead?
Expected output is to filter the records which doesn't have the letter or word 
specified in the wildcard character (*P* or *Pending*).

Instead i am unable to filter as expected.


What version of the product are you using? On what operating system?
Os:Windows. 
Please provide any additional information below.


Original issue reported on code.google.com by [email protected] on 15 Jul 2011 at 11:23

question

Sorry, I couldn't find your email address.

Douglas Crockford says that his json2.js just uses the browser's json object to 
parse json, if the browser has a json.  Does yours do that?  I'm assuming that 
it's safe to do. ( rusty dot wright at gmail dot com )

I was using json2.js but it seems to be causing a problem with google maps so 
I'm going to give yours a try.

Thanks.


Original issue reported on code.google.com by [email protected] on 22 Apr 2011 at 10:13

Error in Chrome

rome Version       : <Copy from: 'about:version'>
URLs (if applicable) : http://code.google.com/p/json-sans-eval/
Other browsers tested:
  Add OK or FAIL after other browsers where you have tested this issue:
     Safari 5: -
  Firefox 4.x: OK
       IE 7/8/9: OK

What steps will reproduce the problem?
1. jsonParse(this.XmlHttp.responseText)


What is the expected result?

   Json Object in the same order

What happens instead?

   {
    "calificacionesGrafico":
    {
     "datos":
        [
         {"5330008":74,"5046729":64}, <---------||||
         {"5330008":58,"5046729":73}  <---------||||
        ],
     "series":
        [
         {"displayName":"Xellers","yField":"Pablo Marchesi","tip":"Pablo Marchesi"},
         {"displayName":"Xellers","yField":"Pablo Marchesi","tip":"Pablo Marchesi"}
        ]
    },
 "calificaciones":
    [
        {"nombreUsuarioDT":"Pablo Marchesi","nombreEquipo":"Xellers","ptosAcumulados":"132","posGral":"404.731"},
        {"nombreUsuarioDT":"Agustin Eduardo Bazzani","nombreEquipo":"Sagrada Familia FC","ptosAcumulados":"137","posGral":"315.102"}
    ]
}

    RETURN JSON OBJECT
    calificaciones: Array[2]
        0: Object
            nombreEquipo: "Xellers"
            nombreUsuarioDT: "Pablo Marchesi"
            posGral: "404.731"
            ptosAcumulados: "132"
            __proto__: Object
        1: Object
            nombreEquipo: "Sagrada Familia FC"
            nombreUsuarioDT: "Agustin Eduardo Bazzani"
            posGral: "315.102"
            ptosAcumulados: "137"
            __proto__: Object
        length: 2
        __proto__: Array[0]
    calificacionesGrafico: Object
        datos: Array[2]
            0: Object
                5046729: 64 <---------||||
                5330008: 74 <---------||||
                __proto__: Object
            1: Object
                5046729: 73 <---------||||
                5330008: 58 <---------||||
        __proto__: Object
        length: 2
        __proto__: Array[0]

    series: Array[2]
    __proto__: Object
    __proto__: Object


 The keys are not in the same order.
 But it would be an expected behavior, a comparison of what other browsers

Regards..

Pablo Marchesi

Original issue reported on code.google.com by [email protected] on 9 Sep 2011 at 2:17

Can't parse top-level strings

Using json2 to create some JSON, jsonParse fails to parse it because it
expects only lists or objects at the top-level.  The following code throws
an error.

jsonParse(JSON.stringify('hello world'));

From looking at the code, it looks like it will also fail to parse
top-level numbers, booleans, null, ... (anything not a list or object).

Original issue reported on code.google.com by [email protected] on 4 Mar 2009 at 8:17

objects with numeric properties are not interpreted correctly

I'll keep it short:

jsonParse("[[1,2,3],{1:2,2:3}]")

This does not parse correctly - the second item in the array, the object, 
comes out as {undefined:3} rather than {1:2,2:3}

This seems to be the case with any object with numeric properties.

And seems to fail consistently in any browser.


Original issue reported on code.google.com by [email protected] on 23 Nov 2008 at 6:00

how to access multiple records

Hi,

I'm sure this is a simple one for the experienced one but I have spent hours 
trying to find a solution for this an cannot find any suitable documentation:


I m using javascript and would like to convert a string holding JSON 
text-format to an array of objects. 
Example of the string:
var strTest = "{\"myname\":\"George Clooney\",\"myage\":25};" + 
"{\"myname\":\"david copperfield\",\"myage\":45}";  
var myJsonObj = jsonParse(strTest);

I would have expected that myJsonObj would have TWO objects stored in an array 
but it is giving me an error saying
"cont is undefined" 
It is a variable found in the downloaded source:
json-sans-eval.js


thanks alot

Original issue reported on code.google.com by [email protected] on 25 Jul 2011 at 3:57

Error in your example code

I believe your example code should be (myJsonObj.x) instead of (myJson.x)
See the corrected third line below.


var myJson = '{ "x": "Hello, World!", "y": [1, 2, 3] }';
var myJsonObj = jsonParse(myJson);
alert(myJsonObj.x);  // alerts Hello, World!
for (var k in myJson) {
  // alerts x=Hello, World!  and  y=1,2,3
  alert(k + '=' + myJson[k]);
}

By the way, can you PLEASE post an example of how someone can first read a
JSON file into the myJson variable (as a string)?  That's all your code
needs to make it a 5 star piece of code.  

Original issue reported on code.google.com by [email protected] on 22 Sep 2009 at 10:21

Add "try{h=h.match(s);}catch(e){return h;} " to preventing re-parse!

What steps will reproduce the problem?
1. If a json-var has been parsed by jsonParse, There will return undefined.
2. So would like to add a few line to preventing for this.
3. I fix it follow:

window.jsonParse = function () {
    var r = "(?:-?\\b(?:0|[1-9][0-9]*)(?:\\.[0-9]+)?(?:[eE][+-]?[0-9]+)?\\b)",
        k = '(?:[^\\0-\\x08\\x0a-\\x1f"\\\\]|\\\\(?:["/\\\\bfnrt]|u[0-9A-Fa-f]{4}))';
    k = '(?:"' + k + '*")';
    var s = new RegExp("(?:false|true|null|[\\{\\}\\[\\]]|" + r + "|" + k + ")", "g"),
        t = new RegExp("\\\\(?:([^u])|u(.{4}))", "g"),
        u = {
            '"': '"',
            "/": "/",
            "\\": "\\",
            b: "\u0008",
            f: "\u000c",
            n: "\n",
            r: "\r",
            t: "\t"
        };

    function v(h, j, e) {
        return j ? u[j] : String.fromCharCode(parseInt(e, 16))
    }
    var w = new String(""),
        x = Object.hasOwnProperty;
    return function (h, j) {
        try {
            h = h.match(s);
        }
        catch (e) {
            return h;
        }
        var e, c = h[0],
            l = false;
        if ("{" === c) e = {};
        else if ("[" === c) e = [];
        else {
            e = [];
            l = true
        }
        for (var b, d = [e], m = 1 - l, y = h.length; m < y; ++m) {
            c = h[m];
            var a;
            switch (c.charCodeAt(0)) {
            default:
                a = d[0];
                a[b || a.length] = +c;
                b = void 0;
                break;
            case 34:
                c = c.substring(1, c.length - 1);
                if (c.indexOf("\\") !== -1) c = c.replace(t, v);
                a = d[0];
                if (!b) if (a instanceof Array) b = a.length;
                else {
                    b = c || w;
                    break
                }
                a[b] = c;
                b = void 0;
                break;
            case 91:
                a = d[0];
                d.unshift(a[b || a.length] = []);
                b = void 0;
                break;
            case 93:
                d.shift();
                break;
            case 102:
                a = d[0];
                a[b || a.length] = false;
                b = void 0;
                break;
            case 110:
                a = d[0];
                a[b || a.length] = null;
                b = void 0;
                break;
            case 116:
                a = d[0];
                a[b || a.length] = true;
                b = void 0;
                break;
            case 123:
                a = d[0];
                d.unshift(a[b || a.length] = {});
                b = void 0;
                break;
            case 125:
                d.shift();
                break
            }
        }
        if (l) {
            if (d.length !== 1) throw new Error;
            e = e[0]
        } else if (d.length) throw new Error;
        if (j) {
            var p = function (n, o) {
                var f = n[o];
                if (f && typeof f === "object") {
                    var i = null;
                    for (var g in f) if (x.call(f, g) && f !== n) {
                        var q = p(f, g);
                        if (q !== void 0) f[g] = q;
                        else {
                            i || (i = []);
                            i.push(g)
                        }
                    }
                    if (i) for (g = i.length; --g >= 0;) delete f[i[g]]
                }
                return j.call(n, o, f)
            };

            e = p({
                "": e
            }, "")
        }
        return e
    }
}();

Original issue reported on code.google.com by [email protected] on 16 Jul 2010 at 2:33

Attachments:

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.