如何在Angular JS中显示JSON值

时间:2016-01-30 18:10:16

标签: angularjs

我想阅读并使用angular JS显示以下JSON代码。我试过但无法获得输出。

我使用ng-repeat来获取和打印这些数据,但得到空白数据。迭代后货物发货,然后发货,然后迭代到SingleShipment,然后发货,请尝试打印其变量

有人可以帮我修复此代码。

package package_1;

import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import javax.swing.JTextPane;
import javax.swing.SwingUtilities;
import javax.swing.SwingWorker;
import package_1.ProgressBarDemo2.Task;
import javax.swing.JSeparator;
import javax.mail.AuthenticationFailedException;
import javax.mail.Session;
import javax.mail.Store;
import javax.swing.JButton;
import java.awt.Color;
import javax.swing.JTextField;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JTextArea;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.Properties;
import javax.swing.JProgressBar;

public class EmailChecker extends SwingWorker<Void, Void>{

    private JFrame frame;
    private JTextField textField;
    public static boolean state = true;
    public Task task;
    /**
     * Launch the application.
     */
    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
                public void run() {

                    try {
                        EmailChecker window = new EmailChecker();
                        window.frame.setVisible(true);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            });
    }

    public void checkcurrent(String[] _Account,String[] _Pass,JTextArea _textArea,JTextArea _textArea_1,int _i,JProgressBar _progressBar,int _size) throws InterruptedException{

        if(_i<_size && state == true){

            Properties props = System.getProperties();
            props.setProperty("mail.debug", "false");
            props.setProperty("mail.store.protocol", "imaps");
            try {
                Session session = Session.getDefaultInstance(props, null);
                Store store = session.getStore("imaps");
                try {
                    store.connect("imap.mail.yahoo.com", _Account[_i], _Pass[_i]);
                } catch (AuthenticationFailedException e) {
                }
                if(store.isConnected() == true){
                    _textArea.setText(_Account[_i]+"/"+_Pass[_i]+ "\n" + _textArea.getText() );
                }else{

                    _textArea_1.setText(_Account[_i]+"/"+_Pass[_i] + "\n" +_textArea_1.getText());

                }
            } catch (Exception e) {
            }
            _progressBar.setValue(100);
            _i++;
            System.out.println("checked");
            checkcurrent(_Account,_Pass,_textArea,_textArea_1,_i,_progressBar,_size);
        }else{
            state = false;
        } 
    }

    /**
     * Create the application.
     */
    public EmailChecker() {
        initialize();
    }

    /**
     * Initialize the contents of the frame.
     */
    private void initialize() {
        frame = new JFrame();
        frame.getContentPane().setBackground(Color.LIGHT_GRAY);
        frame.setBounds(100, 100, 655, 433);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.getContentPane().setLayout(null);

        JTextPane textPane = new JTextPane();
        textPane.setBounds(10, 34, 100, 140);
        frame.getContentPane().add(textPane);

        JTextPane textPane_1 = new JTextPane();
        textPane_1.setBounds(120, 34, 92, 140);
        frame.getContentPane().add(textPane_1);

        JTextPane textPane_2 = new JTextPane();
        textPane_2.setBounds(332, 34, 92, 140);
        frame.getContentPane().add(textPane_2);

        JTextPane textPane_3 = new JTextPane();
        textPane_3.setBounds(222, 34, 100, 140);
        frame.getContentPane().add(textPane_3);

        JTextPane textPane_4 = new JTextPane();
        textPane_4.setBounds(544, 34, 92, 140);
        frame.getContentPane().add(textPane_4);

        JTextPane textPane_5 = new JTextPane();
        textPane_5.setBounds(434, 34, 100, 140);
        frame.getContentPane().add(textPane_5);

        JTextArea textArea = new JTextArea();
        textArea.setToolTipText("Account Ok");
        textArea.setBounds(10, 222, 292, 154);
        frame.getContentPane().add(textArea);

        JProgressBar progressBar = new JProgressBar();
        progressBar.setMinimum(100);
        progressBar.setBounds(10, 379, 626, 16);
        frame.getContentPane().add(progressBar);

        JTextArea textArea_1 = new JTextArea();
        textArea_1.setBounds(344, 222, 292, 154);
        frame.getContentPane().add(textArea_1);

        JButton btnCheck = new JButton("Check");
        btnCheck.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {

                    String[] Account = textPane.getText().split("\\n");
                    String[] Pass = textPane_1.getText().split("\\n");
                    //String[] Proxy = textPane_2.getText().split("\\n");
                    //String[] Port = textPane_3.getText().split("\\n");
                    //String[] Login = textPane_4.getText().split("\\n");
                    //String[] PassPrx = textPane_5.getText().split("\\n");

                    int size = Account.length;
                    int i = 0;

                    try {
                        checkcurrent(Account,Pass,textArea,textArea_1,i,progressBar,size);
                    } catch (InterruptedException e1) {
                        // TODO Auto-generated catch block
                        e1.printStackTrace();
                    }
                }
            });
        btnCheck.setLocation(280, 185);
        btnCheck.setBackground(Color.WHITE);
        btnCheck.setSize(83, 29);
        frame.getContentPane().add(btnCheck);
    }

    @Override
    protected Void doInBackground() throws Exception {
        return null;
        // TODO Auto-generated method stub
    }
}

1 个答案:

答案 0 :(得分:0)

在您的控制器中:

app.controller('MainCtrl', function($scope) {
  var json = {
  "shipmentsAllInfo": {
    "shipmentSingle": [
      {
        "delivered": "5",
        "exception": "4",
        "intransit": "2",
        "manifest": "1",
        "outForDelivery": "3",
        "shipmentDetails": [
          {
            "referenceNumbers": "2",
            "trackingNumber": "1"
          },
          {
            "referenceNumbers": "4",
            "trackingNumber": "3"
          }
        ],
        "total": "7",
        "upsAccount": "Andrew",
        "voids": "6"
      },
      {
        "delivered": "5",
        "exception": "4",
        "intransit": "2",
        "manifest": "1",
        "outForDelivery": "3",
        "shipmentDetails": [
          {
            "referenceNumbers": "2",
            "trackingNumber": "1"
          },
          {
            "referenceNumbers": "4",
            "trackingNumber": "3"
          }
        ],
        "total": "7",
        "upsAccount": "Andrew",
        "voids": "6"
      }
    ]
  }};

  $scope.shipmentinfo= json.shipmentsAllInfo;        
});

然后在你的HTML中:

<body ng-controller="MainCtrl">
 <table class="table table-bordered" ng-repeat="module in shipmentinfo.shipmentSingle">
 <tr>
    <td>
        <p>delivered: {{ module.delivered }}</p>
        <p>exception: {{ module.exception }}</p>
        The rest of you output
        <div ng-repeat="sd in module.shipmentDetails">
          <p>referenceNumbers: {{ sd.referenceNumbers }}</p>
          <p>trackingNumber: {{ sd.trackingNumber }}</p>

        </div>
        etc...
    </td>
 </tr>
</table>
</body>