无法从以下json获得标题

时间:2016-10-15 00:58:26

标签: javascript json node.js

我将此代码放入我的应用程序中,以json格式返回一些作业提要:

我的代码如下所示:

JobFeed.find().sort('-created').exec(function (err, feeds) {
    if (err) {
        return res.status(400).send({
            message: errorHandler.getErrorMessage(err)
        });
    } else {

        _.forEach(feeds, function (row, key) {
            console.log(row.data.title); // showing undefined
        });

        res.jsonp(feeds);
    }
});

,json如下所示:

  { data:
   { isSaved: null,
     client:
      { lastContractTitle: null,
        feedbackText: '4.78 Stars, based on 13 feedbacks',
        paymentVerificationStatus: 1,
        lastContractPlatform: null,
        totalFeedback: 4.7819242373,
        location: [Object],
        lastContractRid: 0,
        edcUserId: 3728985,
        totalReviews: 13,
        companyRid: 0,
        spentTier: '$7,500+',
        companyName: null },
     amount: { amount: 0, currencyCode: 'USD' },
     createdOn: '2016-10-13T06:30:54+00:00',
     skills: [ [Object], [Object], [Object], [Object] ],
     enterpriseJob: false,
     ciphertext: '~01026b31d972ed826b',
     proposalsTier: null,
     description: 'Hello! We\'re currently searching for a developer with',
     category2: 'Web, Mobile & Software Dev',
     type: 2,
     tierText: 'Intermediate ($$)',
     relevance:
      { hoursInactive: 0,
        id: 208660674,
        publishTime: '1476340265000',
        recommendedEffectiveCandidates: 2,
        effectiveCandidates: 3,
        uniqueImpressions: 0 },
     isApplied: null,
     engagement: '30+ hrs/week',
     recno: 208660674,
     title: 'Server-side and Client-side Game Developer for Indie MMO',
     freelancersToHire: 0,
     maxAmount: { amount: 0, currencyCode: 'USD' },
     duration: 'More than 6 months',
     subcategory2: 'Game Development',
     sticky: false,
     stickyLabel: '',
     feedback: null },
  id: 57ffcdbf717ca50cf0b4cbc1 }
{ data:
   { isSaved: null,
     client:
      { lastContractTitle: null,
        feedbackText: 'No feedback yet',
        paymentVerificationStatus: 1,
        lastContractPlatform: null,
        totalFeedback: 0,
        location: [Object],
        lastContractRid: 0,
        edcUserId: 0,
        totalReviews: 0,
        companyRid: 0,
        spentTier: '$100+',
        companyName: null },
     amount: { amount: 0, currencyCode: 'USD' },
     createdOn: '2016-10-13T06:30:51+00:00',
     skills: [ [Object], [Object], [Object] ],
     enterpriseJob: false,
     ciphertext: '~01c59efb9135ed91d0',
     proposalsTier: null,
     description: 'Hello! We\'re currently searching for a developer with',
     category2: 'Web, Mobile & Software Dev',
     type: 2,
     tierText: 'Entry Level ($)',
     relevance:
      { hoursInactive: 0,
        id: 208660673,
        publishTime: '1476340266000',
        recommendedEffectiveCandidates: 18,
        effectiveCandidates: 74,
        uniqueImpressions: 0 },
     isApplied: null,
     engagement: 'Less than 10 hrs/week',
     recno: 208660673,
     title: 'Wordpress & Stripe developer',
     freelancersToHire: 0,
     maxAmount: { amount: 0, currencyCode: 'USD' },
     duration: 'More than 6 months',
     subcategory2: 'Web Development',
     sticky: false,
     stickyLabel: '',
     feedback: null },
  id: 57ffcdbf717ca50cf0b4cbc2 }
{ data:
   { isSaved: null,
     client:
      { lastContractTitle: null,
        feedbackText: 'No feedback yet',
        paymentVerificationStatus: 5,
        lastContractPlatform: null,
        totalFeedback: 0,
        location: [Object],
        lastContractRid: 0,
        edcUserId: 0,
        totalReviews: 0,
        companyRid: 0,
        spentTier: 'Less than $100',
        companyName: null },
     amount: { amount: 2000, currencyCode: 'USD' },
     createdOn: '2016-10-13T06:30:18+00:00',
     skills: [ [Object], [Object] ],
     enterpriseJob: false,
     ciphertext: '~0101449f91585e8e16',
     proposalsTier: null,
     description: 'I need a Christmas card app before 15th Dec.n',
     category2: 'Web, Mobile & Software Dev',
     type: 1,
     tierText: 'Intermediate ($$)',
     relevance:
      { hoursInactive: 0,
        id: 208660669,
        publishTime: '1476340233000',
        recommendedEffectiveCandidates: 7,
        effectiveCandidates: 52,
        uniqueImpressions: 0 },
     isApplied: null,
     engagement: null,
     recno: 208660669,
     title: 'Christmas Card iPhone App',
     freelancersToHire: 0,
     maxAmount: { amount: 0, currencyCode: 'USD' },
     duration: null,
     subcategory2: 'Mobile Development',
     sticky: false,
     stickyLabel: '',
     feedback: null },
  id: 57ffcdbf717ca50cf0b4cbc3 }
{ data:
   { isSaved: null,
     client:
      { lastContractTitle: null,
        feedbackText: '4.88 Stars, based on 102 feedbacks',
        paymentVerificationStatus: 1,
        lastContractPlatform: null,
        totalFeedback: 4.8843944128,
        location: [Object],
        lastContractRid: 0,
        edcUserId: 0,
        totalReviews: 102,
        companyRid: 0,
        spentTier: '$25,000+',
        companyName: null },
     amount: { amount: 100, currencyCode: 'USD' },
     createdOn: '2016-10-13T06:30:00+00:00',
     skills:
      [ [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object] ],
     enterpriseJob: false,
     ciphertext: '~01a04eab3b05372652',
     proposalsTier: null,
     description: 'Hello! We\'re currently searching for a developer with',
     category2: 'Writing',
     type: 1,
     tierText: 'Entry Level ($)',
     relevance:
      { hoursInactive: 0,
        id: 208660668,
        publishTime: '1476340202000',
        recommendedEffectiveCandidates: 2,
        effectiveCandidates: 6,
        uniqueImpressions: 0 },
     isApplied: null,
     engagement: null,
     recno: 208660668,
     title: 'Filipino Blog/Content Writers For a Filipino Site (Using WordPress)',
     freelancersToHire: 3,
     maxAmount: { amount: 0, currencyCode: 'USD' },
     duration: null,
     subcategory2: 'Article & Blog Writing',
     sticky: false,
     stickyLabel: '',
     feedback: null },
  id: 57ffcdbf717ca50cf0b4cbc4 }

我拥有的foreach似乎遍历每个项目,但我无法获得每个项目的标题。任何帮助?

1 个答案:

答案 0 :(得分:0)

我不确定你要做什么,但如果数据确实与你的评论相符,那么这样的事情应该有效:

feeds.forEach(function(feed){
  console.log(feed.data.title);
});

如果您想要更快的性能,请使用常规for循环。我在我的项目中对此进行了测试。如果这不起作用,请告诉我。