2017-04-04 1 views
-6

hey ich bin wirklich neu zu Knoten und AngularJS und ich bin ein Projekt auf Knoten und AngularJS tun i ein Client und Server-Knoten haben Server auf einem Port 3001 läuft und Client auf 3000 läuft, wenn ich meine Server laufen, ich bekommen Daten in einem jSON-Format, aber das Daten ist hier nicht in einem richtigen jSON-Format sind die Daten iWie können Daten im JSON-Format angezeigt werden?

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 

i in Client-Seite wie Design-Token-Format für die ex-Farbe-blau diese Daten angezeigt werden müssen vom Server empfange , farb weiß, Farbe-black etc hier ist mein Code AngularJS die aus

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); 

}); 
}); 
setzen zu erhalten

das ist mein 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> 

bitte helfen Sie mir mit diesem

+0

Wenn ich verstehe, ist Ihr Problem, dass Sie nicht in der Lage sind, den Junk von der JSON-Antwort zu entfernen, um die korrekten Daten auf Ihrer Client-Seite anzuzeigen? – arqam

+0

Ja, ich muss diese Dschunken entfernen, aber ich weiß nicht, wie man diese Dschunken entfernt f – Sushma

+0

Was? Hast du die Saite wirklich angeschaut? Es ist überhaupt kein JSON, nicht das geringste, nicht einmal annähernd. Es ist eine Zeichenfolge, die einige Zeichen enthält, die auch in einer JSON-Zeichenfolge enthalten sind. Nichts mehr – devnull69

Antwort

0

Was haben Sie eine YAML-Datei ist.

Was Sie tun müssen, ist es zu lesen, interpretieren sie auf ein Objekt JS, dann dieses JS Objekt zu einem JSON konvertieren, die Sie senden können.

'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); 
}); 
Verwandte Themen