Can you help with JSON

Hello.
Well maybe i’m the newbie but i want to learn ionic framework.
I want to make simple app with working json. But can’t do it. I getting always problem.

[
{
    "id": 1,
    "name": "Name One"
},
{
    "id": 2,
    "name": "Name Two"
},
{
    "id": 3,
    "name": "Name Three"
}]

Here is my json example and i wat to do a list from this json. But i had always an error in examples.
Can you write an example from this json please?

Note: Json will be in my server.

Thank You

What is the error you see?

well i see this topic

and i made a controller
.factory(‘PersonService’, function($http){
var BASE_URL = “http://sefasaiddeniz.com/package.json”;
var items = [];

    return {
        GetFeed: function(){
            return $http.get(BASE_URL).then(function(response){
                items = response.data.results;
                return items;
            });
        }
    }
})
.controller('MyCtrl', function($scope, $timeout, PersonService) {
    $scope.items = [];

    PersonService.GetFeed().then(function(items){
        $scope.items = items;
    });


})

like this
then

  <ion-list>

      <ion-item  ng-repeat="item in items">

          <h2>{{item.id}}</h2>
          <p>{{item.name}}</p>
      </ion-item>
  </ion-list>

i write this like example
and change my json
http://www.sefasaiddeniz.com/package.json
but i see nothing :frowning:

If you are working locally and according to your code you are probably getting this:

XMLHttpRequest cannot load http://sefasaiddeniz.com/package.json. No ‘Access-Control-Allow-Origin’ header is present on the requested resource…

But maybe that is not what you see. Again, what is the error?

XMLHttpRequest cannot load http://sefasaiddeniz.com/package.json. No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin ‘http://localhost:8100’ is therefore not allowed access.

in console i have this error same like you

Hello
I solve problem. Thank you for all.

I solved with this
http://ionicinaction.com/how-to-fix-cors-problems-and-no-access-control-allow-origin-header-errors-with-ionic/

if you use chrome ,you can use this plugin

thank you man that will be usefull in local work :smile:

I have a problem now.
Well now i don’t want make a list I want to get an id and name my json is

[
{
"id": 1,
"name": "Name One"
}
]

in examples makes alwasy a list but i want to show just id and name not like list. how can i do that? Can you give a little example.
(sorry for bad english)
Thank you

It would expand the api like http://www.sefasaiddeniz.com/package.json/1… and query one item.

Else you could filter data

return $http.get(BASE_URL).then(function(response){
var item= $filter('filter')(response.data.results, {id:1})[0];
return item;  

$scope.item= item;
alert($scope.item.name) // Name One