Unnamed json result

Hi All,

Dumb question, I’m (I think) successfully retreaving some JSON data from a server using fetch. The problem is that my JSON data doesn’t have a name for the container, it looks like this:

[
  {
    "Field1": "somedata",
    "Field2": "somemoredata"
  }, 
  {
    "Field1": "somedata",
    "Field2": "somemoredata"
  }
]

I’m assigning the resultset I’m retrieving to an observable and attempting to use a block like so:

<Each Items="{resultset}">
...
</Each>

Doesn’t seem to work. In the examples like https://www.fusetools.com/examples/http-json the result set is named and is included as:

<Each Items="{resultset.resultname}">
...
</Each>

No idea if this is my problem or not.

Also is there a way to output what I’ve fetched to the console so I can check it? So far if I output it I just get a bunch of: [object Object],[object Object],[object Object] things, suggests I’ve indeed fetched my resultset but doesn’t really tell me much more :slight_smile:

Just a small amendum…

var resultset = Observable();

...
// in my fetch:

resultset.value = jsonresult;
console.log(JSON.stringify(resultset.value));
...

I can definately see my result set in the log so I’m pretty sure I’m fetching the data properly, no idea why I can’t display it yet:)

For <Each> to work your Observable must have several values. You are setting the first value of your Observable to an array. Try

resultset.replaceAll(jsonresult);

Hey Bjorn,

Figured it be something along those lines. The replaceAll didn’t work but I did manage to get it to work like so:

for (var i in jsonresult) {
  resultset.add(jsonresult[i]);
};

Just need to clear my variable before hand as it now always appends on a reload but I’m getting close…

Not sure why the resultAll won’t work, does seem that should have done the trick.

Cheers,

Bas

I agree that replaceAll should work. Maybe you can post a self-contained test-case so that we can reproduce the error? (Inline the json structure)

Try

resultset.value = jsonresult;
resultset.expand();

Hey Bjorn,

Nah same result interestingly enough.

It’s getting late this side of the world so I’m going to catch some z’s. I’ll see if I can get a simple example going tomorrow. Be good to know what I"m overlooking:)

Cheers for the help,

Bas