download1002
2016-06-03 13:55
浏览 53

如何读取JSON嵌套在Angular JS $ http服务中?

This is my main JSON file

{
  "chartType" : ["column", "column", "pie"],
  "chartTitle": ["Cantidad de equipos", "Cantidad de artículos consumibles","Cantidad de empleados a cargo"],
  "yAxisTitle": ["Equipos", "Consumibles", "Empleados"],
  "seriesName": ["conexion_equipos_basededatos_json.php", "conexion_consumibles_basededatos_json.php", "conexion_basededatos_json.php"],
  "seriesData": ["conexion_equipos_basededatos_json.php", "conexion_consumibles_basededatos_json.php", "conexion_basededatos_json.php"]
}

That loads others PHP JSON_ENCODE files in "seriesName" and "seriesData".

These JSON results generate keys "id" and "nombre" (spanish word for name).

How read values for these keys through Angular Service $http.get of the main JSON?

**UPDATE (06/03/2016)**

I'm middle of road!

I read the JSON objects from "seriesName" array with angular.fromJson function as follow:

var deserialize = angular.FromJson(data);

var objects = deserialize.seriesName;

console.log(objects);

That's throws me an array of objects:

 ["conexion_equipos_basededatos_json.php", "conexion_consumibles_basededatos_json.php", "conexion_basededatos_json.php"]

Thus, how I could read the objects contained in these URL's through Angular?

图片转代码服务由CSDN问答提供 功能建议

这是我的主要JSON文件

  {
“  chartType“:[”column“,”column“,”pie“],
”chartTitle“:[”Cantidad de equipos“,”Cantidaddeartículosconsumibles“,”Cantidad de empleados a cargo“],
”yAxisTitle  “:[”Equipos“,”Consumibles“,”Empleados“],
”seriesName“:[”conexion_equipos_basededatos_json.php“,”conexion_consumibles_basededatos_json.php“,”conexion_basededatos_json.php“],
”seriesData“:[”  conexion_equipos_basededatos_json.php“,”conexion_consumibles_basededatos_json.php“,”conexion_basededatos_json.php“] 
} 
   
 
 

在”seriesName“和”seriesData“中加载其他PHP JSON_ENCODE文件 “。

这些JSON结果生成键”id“和”nombre“(西班牙语中的名称)。

如何通过主JSON的Angular Service $ http.get读取这些键的值?

** UPDATE(06/03) / 2016)**

我已经走到了路边!

我从“seriesName”数组中读取了带有角度的JSON对象 .fromJson函数如下:

  var deserialize = angular.FromJson(data); 
 
var objects = deserialize.seriesName; 
 
console.log(objects);  
   
 
 

这会抛出一个对象数组:

  [“conexion_equipos_basededatos_json.php”,“conexion_consumibles_basededatos_json.php  “,”conexion_basededatos_json.php“] 
   
 
 

因此,我如何通过Angular读取这些URL中包含的对象?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • doujiushi9007 2016-06-23 14:09
    已采纳

    Altough have button, I could resolve this issue.

    I have created a repository that integrates Angular.js, PHP, and Highcharts, with Materialize.css, adding series dynamically from external JSON.

    link: https://github.com/Nullises/DynamicSeriesHighchartsAngular

    点赞 打赏 评论
  • doumengyin0491 2016-06-03 14:05

    First of all you need to decode the JSON in PHP using json_decode(), then you treat the result as an object.

    Try something like;

    $data = xyz; // pass in the JSON object
    $res = json_decode($data); // decode JSON
    $chartType = $res->chartType; // access property as an object
    

    You can also try var_dump($res) to get a clearer understanding of the structure and how to access it;

    点赞 打赏 评论
  • donglu9445 2016-06-03 14:12

    You can do following.

    $http.get('url_to_json').then(fucntion(response) {
      var myJson = response.data;
      var keys = Object.keys(myJson);
        console.log('Your keys', keys);
    }, fucntion(error) {
    
    });
    
    点赞 打赏 评论

相关推荐 更多相似问题