2017-04-04 147 views
-6

嘿其實我是新來的節點和angularjs,我正在做一個節點和angularjs項目我有一個客戶端和服務器節點服務器運行在端口3001和客戶端運行在3000每當我運行我的服務器我會得到一個在一個JSON格式的數據,但這些數據是不是在這裏正確的JSON格式的數據我從服務器接收如何以json格式顯示數據?

color : 
    white : &color-white "#FFFFFF" 
    black : &color-black "#262626" 
    neutral : 
    20 : &color-neutral-20 "#222222" 
    90 : &color-neutral-90 "#EEEEEE" 
    blue: 
    50: &color-blue-50 "#0000ff" 
    90: &color-blue-60 "#3333ff" 
    red: 
    50: &color-red-90 "#ff0000" 
    95: &color-red-90 "#ff8080" 
    Green: 
    40: &color-green "#00cc00" 
    80: &color-green "#99ff99" 
    Pink: 
    80: &color-pink "#ff99cc" 
    30: &color-pink "#ff0080" 
    Yellow: 
    70: &color-yellow "#ffff66" 
    40: &color-yellow "#ffff00" 

    border: 
    brand: &color-border-brand "#1589ee" 
    brand-dark: &color-border-brand-dark "#0070d2" 
    customer: &color-border-customer "#ff9a3c" 
    destructive: &color-border-destructive "#c23934" 
    destructive-hover: &color-border-destructive-hover "#a61a14" 


    interactive-color : 
    default: *color-blue-50 
    dark: *color-blue-60 

    background-color : 
    default : *color-white 
    light : *color-neutral-90 
    dark : *color-neutral-20 
    disabled: *color-neutral-90 

    text-color : 
    default : *color-neutral-20 
    on-light : *color-neutral-20 
    on-dark : *color-white 
    light : *color-neutral-20 
    disabled : *color-neutral-20 
    link : 
     default : *color-blue-50 
     on-dark : *color-white 

font: 
    family: 
    text: &font-family-text "Salesforce Sans" 
    heading: &font-family-heading "Arial" 

    weight: 
    light: &font-weight-light "300" 
    regular: &font-weight-light "300" 
    bold: &font-weight-light "300" 

    size: 
    xx-small: &font-size-text-xx-small ".625rem FONT_SIZE_1 10px" 
    x-small: &font-size-text-x-small ".75rem FONT_SIZE_2 12px" 
    small: &font-size-text-small ".8125rem FONT_SIZE_3 13px" 
    medium: &font-size-text-medium ".1rem FONT_SIZE_5 16px" 
    large: &font-size-text-large "1.125rem FONT_SIZE_6 18px" 
    x-large: &font-size-text-x-large "1.25rem FONT_SIZE_7 20px" 

    line-height: 
    heading: &line-height-heading "1.25" 
    text: &line-height-text "1.5" 
    reset: &line-height-reset "1" 
    tab: &line-height-tab "2.5rem 40px" 
    button: &line-height-button "1.875rem 30px" 
    button-small: &line-height-button-small "1.75rem 28px" 

space : 
    default : 16px 
    xxs: 2px 
    xs: 4px 
    s: 8px 
    m: 16px 
    l: 32px 
    xl: 64px 
    inset : 
    default : 16px 16px 16px 16px 
    xxs : 2px 2px 2px 2px 
    xs : 4px 4px 4px 4px 
    s : 8px 8px 8px 8px 
    m : 16px 16px 16px 16px 
    l : 32px 32px 32px 

我需要顯示像前顏色藍色設計令牌格式此數據在客戶端,顏色白色,顏色黑色等 這裏是我的angularjs代碼接收輸出

angular.module('design',[]).controller('designController', 
function($scope,$http) 
{ 
$scope.message="hii"; 
console.log(":outside"); 
$http.get('http://rest- 
service.guides.spring.io/greeting').then(function(response) 
{ 
console.log("inside"); 
$scope.greeting = Json.stringify(response.data); 

}); 
}); 

這是我的index.html

<!DOCTYPE html> 
<html> 
<head> 
<title></title> 
<meta charset="utf-8" /> 
<link 
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" 
rel="stylesheet"> 
<script 
src="http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.2/angular.js"> 
</script> 

</head> 
<body ng-app="design" class="container"> 
<br/> 
<br /> 
<br /> 

<div class="row" style="background-color:purple;"> 
<font color="white">ellucian University</font> 
</div> 
<br/> 
<br/> 
<div class="row"> 
<div class="col-sm-4"> 
<font color="purple">Design Tokens</font> 
</div> 
<div class="col-sm-8" align="right"> 
<input type="button"class="btn btn-primary" value="download" /> 
    <input type="button" class="btn btn-primary" value="Save" /> 
</div> 
<br/> 
<br/> 

</div> 
<div ng-controller="designController" class="row"> 
<div class="col-sm-4"> 
<font color="purple">Tokens</font><br/> 
<li ng-repeat = "item in greeting track by $index"> 
{{item}} 
</li> 
</body> 
</html> 

請幫我這個

+0

如果我明白了,您的問題是您無法從JSON響應中刪除垃圾來顯示客戶端的正確數據? – arqam

+0

是的,我需要刪除這些垃圾但我不知道如何刪除這些垃圾f – Sushma

+0

什麼?你真的看了看弦嗎?它根本不是JSON,沒有絲毫的,甚至沒有接近。它是一些包含一些JSON字符串中包含的字符的字符串。沒有更多 – devnull69

回答

0

你有什麼是YAML文件。

你需要做的是讀取它,將其解釋爲JS對象,然後將此JS對象轉換爲可發送的JSON。

'use strict'; 

const yaml = require('js-yaml'), 
    fs = require('fs'); 


Promise.resolve().then(() => { 
    return new Promise((resolve, reject) => { 
     fs.readFile('your/yaml/file.yaml', (error, data) => { 
      if(error) { 
       reject(error); 
      } else { 
       resolve(data); 
      } 
     }); 
    }); 
}).then((data) => { 
    let doc = yaml.safeLoad(data); 
    return Promise.resolve(doc); 
}).then((doc) => { 
    let json = JSON.stringify(doc); 
    console.log('JSON: ' + json); 
    return Promise.resolve(); 
}).then(() => { 
    console.log('OK'); 
}).catch((error) => { 
    console.log('Error: ' + error); 
});