GVKun编程网logo

如何访问 Json Object Laravel Blade 中的值(如何访问json对象)

25

最近很多小伙伴都在问如何访问JsonObjectLaravelBlade中的值和如何访问json对象这两个问题,那么本篇文章就来给大家详细解答一下,同时本文还将给你拓展Angular-在null{"e

最近很多小伙伴都在问如何访问 Json Object Laravel Blade 中的值如何访问json对象这两个问题,那么本篇文章就来给大家详细解答一下,同时本文还将给你拓展Angular - 在 null {"exception":"[object] (Error(code: 0) in Laravel API、angular – 无法解析AuthenticationService的所有参数:([object Object],?,[object Object])、AngularJS:textarea绑定到JSON对象显示“object-object”、fastjson 包下的 JSON.parseObject 只需要一段 string,不需要 class 信息,是如何做到转化成 Object 的?等相关知识,下面开始了哦!

本文目录一览:

如何访问 Json Object Laravel Blade 中的值(如何访问json对象)

如何访问 Json Object Laravel Blade 中的值(如何访问json对象)

如何解决如何访问 Json Object Laravel Blade 中的值?

我只想访问这个 json 对象中的“电梯”值。 如何在 Laravel 刀片模板中执行此操作?

谢谢!

{"delivery_floor":null,"pickup_floor":null,"Elevator":"Yes","Elevator2":"Yes","disassembled":"Yes","reassembled":"Yes","shipment_title":""}

解决方法

您必须使用以下代码

@php $jsonDecodeValue = json_decode($your_variable,true); @endphp
{{ $jsonDecodeValue[''Elevator'']}}

Angular - 在 null {

Angular - 在 null {"exception":"[object] (Error(code: 0) in Laravel API

如何解决Angular - 在 null {"exception":"[object] (Error(code: 0) in Laravel API?

我有一个安装项目,使用 Angular-12 作为前端,使用 Laravel-8 作为后端。我想用徽标存储公司详细信息。徽标名称应存储在名为 company_logo 的 DB 字段中,而徽标(图像)本身应存储在目录文件夹中。

Laravel 后端控制器:

public function register(StoreCompanySetupRequest $request)
{
        $arr_company = [
            ''name''                              => $request->companyName,''registration_number''               => $request->registrationNumber,];

         if ($request->company_logo != "") {
             $company_logo = $request->file(''company_logo'');
             $new_name = rand() . ''.'' . $company_logo->getClientOriginalExtension();
             $company_logo->move(public_path(''storage/images/company_logo''),$new_name);
             $arr_company[''company_logo''] = $new_name;
        }
        $newCompany = Company::create($arr_company);
}

角度:

组件:

    export class SignupCompanyComponent implements OnInit {
      isLinear = true;
      isLoading = false;
      companySetupForm!: FormGroup;
      companyForm!: FormGroup;
      idForm!: FormGroup;
      imageSrclogo!: string | ArrayBuffer;

  onFileChange(event: any) {
    const reader = new FileReader();

    if(event.target.files && event.target.files.length) {
      const [file] = event.target.files;
      reader.readAsDataURL(file);

     reader.onload = () => {
        this.imageSrclogo = reader.result as string;

        this.companyInfoForm.patchValue({
          fileSource: reader.result
        });
      };

    }
  }

      ngOnInit() {
        this.companyForm = this.fb.group({
          companyName: ['''',[Validators.required,Validators.minLength(3),Validators.maxLength(100)]],company_logo: ['''',[
        RxwebValidators.extension({
          extensions: ["jpg","jpeg","bmp","png","gif","svg"]
        })
      ]],},{ updateOn: "blur" });
        this.idForm = this.fb.group({
          registrationNumber: ['''',});
      }

      get fc() {
        return this.companyForm.controls;
      };
      get fi() {
        return this.idForm.controls;
      };

  onSubmit() {
    this.isSubmitted = true;

    const formCompanyData = this.companyForm.getRawValue();
    const formIdData = this.idForm.getRawValue();

    const data = {
      companyName: formCompanyData.companyName,company_logo: formCompanyData.company_logo,registrationNumber: formCompanyData.registrationNumber,};

    this.spinnerService.show();
    const header = {
      ''Content-Type'': ''application/json''
    };

    this.isLoading = true;
    return this.api.post(''companies/company/signup'',data,header)
      .pipe(first())
      .subscribe(
        data => {
          this.tokenHandler(data);
        });
  }
}

HTML:

<mat-horizontal-stepper [linear]="isLinear" #stepper labelPosition="bottom">
  <mat-step [stepControl]="companyForm">
    <form [formGroup]="companyForm">
      <ng-template matStepLabel matStepperIcon="phone">Company Info</ng-template>

      <div>
        <div>
          <divhttps://www.jb51.cc/tag/Box/" target="_blank">Box-profile">
            <div>
              <img[src]="imageSrclogo || ''assets/img/no-image.png''" alt="No Company logo">
            </div>

            <h3>Company logo</h3>

            <div>
              <label for="file"></label>
              <input formControlName="company_logo" id="file" type="file"(change)="onFileChange($event)">
            </div>
          </div>
        </div>
      </div>

      <div>
        <div>
          <label for="name">Company Name:<span>*</span></label>}
          <input type="text" formControlName="companyName" placeholder="Company Name"required/>
        </div>
        <div *ngIf="fc.companyName.touched && fc.companyName.invalid">
          <div *ngIf="fc.companyName.hasError(''required'')">
            <div>
              Company Name is required!
            </div>
          </div>
          <div *ngIf="fc.companyName.hasError(''minlength'')">
            <div>
              Company Name cannot be less than 3 characters!
            </div>
          </div>
          <div *ngIf="fc.companyName.hasError(''maxlength'')">
            <div>
              Company Name cannot be more than 100 characters!
            </div>
          </div>
        </div>
      </div>
      <div>
        <button mat-raised-button color="primary" matStepperNext [disabled]="companyForm.status != ''VALID''">Next</button>
      </div>
    </form>
  </mat-step>
  <mat-step [stepControl]="idForm">
    <form [formGroup]="idForm">
      <ng-template matStepLabel>Company ID</ng-template>
      <div>
        <div>
          <label for="registration_number">Registration Number:<span>*</span></label>
          <input type="text" formControlName="registrationNumber" placeholder="Registration Number"required/>
        </div>
        <div *ngIf="fi.registrationNumber.touched && fi.registrationNumber.invalid">
          <div *ngIf="fi.registrationNumber.hasError(''required'')">
            <div>
              Company Reg. No. is required!
            </div>
          </div>
          <div *ngIf="fi.registrationNumber.hasError(''maxlength'')">
            <div>
              Company Reg. No. cannot be more than 100 characters!
            </div>
          </div>
        </div>
      </div>
      <div>
        <button mat-raised-button color="black" matStepperPrevIoUs>Back</button> &nbsp;
        <button mat-raised-button color="success" [disabled]="isLoading" type="submit" (click)="onSubmit()">
                    <span *ngIf="isLoading"></span>
                      Submit
                  </button> &nbsp;
        <button mat-raised-button color="warn" (click)="stepper.reset()">Reset</button>
      </div>
  </mat-step>
</mat-horizontal-stepper>

当我提交时,什么都没有保存到数据库中。

我在提交时执行了 console.log(data) 并得到了这个响应:

{companyName: "ssasa",: registrationNumber: "sasaas",company_logo: "C:\\fakepath\\token.PNG",…}
companyName: "ssasa"
registrationNumber: "sasaas"
company_logo: "C:\\fakepath\\token.PNG"

然后当我检查 laravel.log 时,我得到了这个:

local.ERROR: 调用成员函数 getClientOriginalExtension() on null {"exception":"[object] (Error(code: 0)

它指向这一行:

$new_name = rand() 。 ''.'' . $company_logo->getClientOriginalExtension();

如何解决这个问题?

谢谢

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

angular – 无法解析AuthenticationService的所有参数:([object Object],?,[object Object])

angular – 无法解析AuthenticationService的所有参数:([object Object],?,[object Object])

我遇到了下一个错误,无法理解如何解决它.

Can’t resolve all parameters for AuthenticationService: ([object Object],?,[object Object])

我已经检查了几乎每个主题,并尝试了多种方法来解决它,但仍然无法在第二天击败它.

我试图像这样在appService中注入第一个authService但是得到了同样的错误

@Inject(forwardRef(() => AuthenticationService)) public authService: AuthenticationService

我检查了所有DI和服务内部的导入顺序,在我看来一切都是正确的

如果有人可以帮我处理它,我很感激.

Angular 4.0.0

AuthService

import { Injectable } from '@angular/core';
import {Http,Headers,Response} from '@angular/http';
import 'rxjs/add/operator/toPromise';
import {Observable} from 'rxjs/Rx';

import {AppServices} from "../../app.services";
import {Router} from "@angular/router";

@Injectable()
export class AuthenticationService {
  public token: any;

  constructor(
    private http: Http,private appService: AppServices,private router: Router
  ) {
    this.token = localStorage.getItem('token');
  }

  login(username: string,password: string): Observable<boolean> {
    let headers = new Headers();
    let body = null;
    headers.append("Authorization",("Basic " + btoa(username + ':' + password)));

    return this.http.post(this.appService.api + '/login',body,{headers: headers})
      .map((response: Response) => {
        let token = response.json() && response.json().token;
        if (token) {
          this.token = token;
          localStorage.setItem('Conform_token',token);
          return true;
        } else {
          return false;
        }
      });
  }

  logout(): void {
    this.token = null;
    localStorage.removeItem('Conform_token');
    this.router.navigate(['/login']);
  }
}

应用服务

import {Injectable} from '@angular/core';
import {Headers,Http,RequestOptions} from '@angular/http';
import {Router} from "@angular/router";
import {AuthenticationService} from "./auth/auth.service";

import 'rxjs/add/operator/toPromise';
import {Observable} from 'rxjs/Rx';

@Injectable()

export class AppServices {

  api = '//endpoint/';

  public options: any;
  constructor(
    private http: Http,private router: Router,public authService: AuthenticationService // doesn't work
  //  @Inject(forwardRef(() => AuthenticationService)) public authService: AuthenticationService // doesn't work either
      ) {
        let head = new Headers({
      'Authorization': 'Bearer ' + this.authService.token,"Content-Type": "application/json; charset=utf8"
    });
    this.options = new RequestOptions({headers: head});
  }

  // ====================
  //    data services
  // ====================

  getData(): Promise<any> {
    return this.http
      .get(this.api + "/data",this.options)
      .toPromise()
      .then(response => response.json() as Array<Object>)
      .catch((err)=>{this.handleError(err);})
  }

应用模块

import { browserModule } from '@angular/platform-browser';
import { browserAnimationsModule } from '@angular/platform-browser/animations';

import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import {BaseRequestOptions,HttpModule} from '@angular/http';

import { MaterialModule} from '@angular/material';
import {FlexLayoutModule} from "@angular/flex-layout";
import 'hammerjs';

import { routing,appRoutingProviders }  from './app.routing';
import { AppServices } from './app.services';
import {AuthGuard} from "./auth/auth.guard";
import {AuthenticationService} from "./auth/auth.service";

import {AppComponent} from './app.component';
import {AuthComponent} from './auth/auth.component';
import {NotFoundComponent} from './404/not-found.component';
import { HomeComponent } from './home/home.component';

@NgModule({
  declarations: [
    AppComponent,AuthComponent,NotFoundComponent,HomeComponent
  ],imports: [
    browserModule,browserAnimationsModule,FormsModule,HttpModule,routing,MaterialModule,FlexLayoutModule
  ],providers: [AppServices,AuthGuard,AuthenticationService],bootstrap: [AppComponent]
})
export class AppModule { }

解决方法

AppServices和AuthenticationService之间存在循环依赖关系 – 这与Angular使用的构造函数注入无法实现.

你可以使用

export class AuthenticationService {
  public token: any;
  appService: AppServices;
  constructor(
    private http: Http,// private appService: AppServices,injector:Injector;
    private router: Router
  ) {
    setTimeout(() => this.appService = injector.get(AppServices));
    this.token = localStorage.getItem('token');
  }

另见DI with cyclic dependency with custom HTTP and ConfigService

要避免使用setTimeout,您还可以从AppService的构造函数中设置AuthenticationService.appService(或者相反)

AngularJS:textarea绑定到JSON对象显示“object-object”

AngularJS:textarea绑定到JSON对象显示“object-object”

我对AngularJS相当新。

我试图绑定一个对象到一个textarea。

HTML:

<textarea rows="5" cols="10" ng-model="menuItem.preset"></textarea>

模型:

{
    "kind": "title","label": "ADD_TITLE","iconSrc": "textTitle.png","experimentInclude": "","experimentExclude": "three","preset": {
        "compType": "richTitle","styleId": "txtNew"
    }
}

结果:

如何显示JSON字符串化(然后再将其另存为对象)?

我刚刚研究了我相信是最“正确”的方式这样做,因为我需要它为我的 https://github.com/vorburger/MUI.js …所以 here is a Plonker与我的解决方案。它基于&本质上是一个特殊情况(即应用程序)相关的Q How to do two-way filtering in angular.js?附加的扭曲是模型更新也应该改变文本框..这是$ watch / $ setViewValue / $ render事情。
var app = angular.module('app',[]);

app.directive('jsonText',function() {
  return {
    restrict: 'A',// only activate on element attribute
    require: 'ngModel',// get a hold of NgModelController
    link: function(scope,element,attrs,ngModelCtrl) {

      var lastValid;

      // push() if faster than unshift(),and avail. in IE8 and earlier (unshift isn't)
      ngModelCtrl.$parsers.push(fromUser);
      ngModelCtrl.$formatters.push(toUser);

      // clear any invalid changes on blur
      element.bind('blur',function() {
        element.val(toUser(scope.$eval(attrs.ngModel)));
      });

      // $watch(attrs.ngModel) wouldn't work if this directive created a new scope;
      // see http://stackoverflow.com/questions/14693052/watch-ngmodel-from-inside-directive-using-isolate-scope how to do it then
      scope.$watch(attrs.ngModel,function(newValue,oldValue) {
        lastValid = lastValid || newValue;

        if (newValue != oldValue) {
          ngModelCtrl.$setViewValue(toUser(newValue));

          // Todo avoid this causing the focus of the input to be lost..
          ngModelCtrl.$render();
        }
      },true); // MUST use objectEquality (true) here,for some reason..

      function fromUser(text) {
        // Beware: trim() is not available in old browsers
        if (!text || text.trim() === '') {
          return {};
        } else {
          try {
            lastValid = angular.fromJson(text);
            ngModelCtrl.$setValidity('invalidJson',true);
          } catch (e) {
            ngModelCtrl.$setValidity('invalidJson',false);
          }
          return lastValid;
        }
      }

      function toUser(object) {
        // better than JSON.stringify(),because it formats + filters $$hashKey etc.
        return angular.toJson(object,true);
      }
    }
  };
});


app.controller('Ctrl',['$scope',function($scope) {
    $scope.model = {};
    $scope.model.data = {
      "kind": "title","styleId": "txtNew"
      }
    };
  }
]);
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<div ng-app="app">
  <div ng-controller="Ctrl">
    <textarea json-text ng-model='model.data' rows="15"></textarea>
    <p>{{ model.data }}</p>
  </div>
</div>

fastjson 包下的 JSON.parseObject 只需要一段 string,不需要 class 信息,是如何做到转化成 Object 的?

fastjson 包下的 JSON.parseObject 只需要一段 string,不需要 class 信息,是如何做到转化成 Object 的?

高春辉、王春生、朱峰:关于开源创业的 15 件小事

如题。

关于如何访问 Json Object Laravel Blade 中的值如何访问json对象的问题我们已经讲解完毕,感谢您的阅读,如果还想了解更多关于Angular - 在 null {"exception":"[object] (Error(code: 0) in Laravel API、angular – 无法解析AuthenticationService的所有参数:([object Object],?,[object Object])、AngularJS:textarea绑定到JSON对象显示“object-object”、fastjson 包下的 JSON.parseObject 只需要一段 string,不需要 class 信息,是如何做到转化成 Object 的?等相关内容,可以在本站寻找。

本文标签:

上一篇Jasper Report - 错误时忽略数字格式(sumproduct忽略错误值)

下一篇Android ConstraintLayout 的 ConstraintSet Java API 删除视图维度?(constraintlayout怎么删除)